cancel
Showing results for 
Search instead for 
Did you mean: 

PATCH/PUT call is creating a new record in SAP CAPM

parthasaradhi
Explorer

Hi Experts,

I have created a CAP application, in which I have few tables and exposed an OData service as well which uses generic handlers.

Now when I am testing the service from rest client, I have observed that when I am trying make a PATCH/PUT call to service with an entry which is not present in the table, it is inserting the record instead of throwing an error.

I need to know whether this is the default behavior of PUT/PATCH in SAP CAP. (say whenever it finds an entry in the table it updates it, if it doesn't find an entry it goes ahead and creates it).


With Regards,

Partha.

abranjan
Active Participant

Hi Partha,

How are you making the PATCH call?
As per my understanding if you are passing a new field entry in the payload while doing PATCH, you would get a deserialization error in CAP.
Error 400: "message": "Deserialization Error: 'Test' does not exist in type 'CatalogService.Employee'."
Something like above.

Best,
Abhijeet

View Entire Topic
marcbecker
Employee
Employee

Yes PATCH and PUT in CAP have UPSERT semantics. This is in line with the OData specification, which states that:

> To update an individual entity, the client makes a PATCH or PUT request to a URL that identifies the entity.

Source: http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_UpdateanEntity

> An upsert occurs when the client sends an update request to a valid URL that identifies a single entity that does not yet exist.

Source: http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_UpsertanEntity