OData API
PATCH Request for updating
With the PATCH request it is possible that you update data in the SAP Sales Cloud
Navigation for OData API
1. Test SAP Sales Cloud OData API with Postman 1.1. OData 1.2. Postman 2. GET Requests 2.1. SAP Sales Cloud Object Collections 2.2 Metadata 2.2.1. Principle 2.2.2. Attributes 2.2.3. SAP-Attributes 2.3. Work with Parameters 2.3.1. Filter 2.3.2. Work with Dates and Datetimes 2.3.3. Orderby 2.3.4. Top 2.3.5. Skip 2.3.6. Format 2.3.7. Select 2.3.8. Count 2.3.9. Inlinecount 2.3.10. Expand 2.4. Examples of GET Requests 2.5. Build OData Queries for Reports 3. X-CSRF-Token 4. POST Request for creating 4.1. Single POST Request 4.2. Create multiple entries with $batch 5. PATCH Request for updating 5.1. Single PATCH Request 5.2. Change multiple entries with $batch 6. DELETE Requests 7. OData Monitor 8. OData Service Explorer 9. Enable customized fields for the API interface 10. Connect Mircosoft Power BI® with SAP Sales Cloud API 11. Deep Links for URL to SAP Sales Cloud Objects
This request consists of three parts: The URL, the header and a body. The x-csrf token is the most important component in the header for updating, since without this token you have no authorization to change the data. In the body you specify which fields are to be updated with which value.
5.1. Single PATCH Request
To be able to update an object you always need the ObjectID. A PATCH request consists of three parts: The Request URL to API, the Collection and the ObjectID. Die ObjectID has to be noted in the request in brackets and apostrophes.
With that said, set the x-csrf-token and content-type for your PATCH query in the header. The content-type defines in which form the body will be written. In this case application/json will be used.
In the next step, you define the body for this query. To do this, click on the Body tab and select the raw type. The content-type JSON will now be displayed again. Make sure to define your JSON input.
There are three possible payloads. The first payload would be the successful one – which has no content. As status you get here: 204 – No Content. The second payload would be if a property – which you have defined in your body – does not exist. And the third possible payload would be if you try to change a property, which is not possible according to the metadata.
Successfully Updated Status: 204 No Content
Property not found: Status: 400 Bad Request
<?xml version="1.0" encoding="utf-8"?> <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code/> <message xml:lang="en">Property 'ABC' not found</message> </error>
Property not updated: Status: 400 Bad Request
<?xml version="1.0" encoding="utf-8"?> <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code>CX_ODATA_ANNOTATION_ERROR</code> <message xml:lang="en">Update not allowed for properties: ID. Check metadata for VisitCollection</message> </error>
5.2. Change multiple entries with $batch
The PATCH request is similar to the POST request. The structure of the header must be exactly the same. Only the body looks slightly different. Again make sure that the lines starting with // are comments and shall be deleted, if you want to use this as a try:
--batch_B01 // the name of the batch request is B01 and was separated // with an underline. As said make sure that this batch is equal // as in the header parameter of content-type Content-Type: multipart/mixed; boundary=changeset_C01 // Start of the changeset C01: --changeset_C01 Content-Type: application/http Content-Transfer-Encoding: binary PATCH VisitCollection('00163EA729061EEBBDCC209B2C03C6AC') HTTP/1.1 // Define the type of request first -> Here: PATCH // Define the collection secondly -> Here: VisitCollection // Provide the ObjectID of the Object you want to update // End with HTTP/1.1 sap-context-accept: header Content-Type: application/json Accept: application/json // JSON input for updating a visit: { "Subject" : "Update Visit", "MainAccountPartyID" : "1229342", "Status" : "2" } // End of changeset_C01 --changeset_C01-- --batch_B01 Content-Type: multipart/mixed; boundary=changeset_C02 --changeset_C02 Content-Type: application/http Content-Transfer-Encoding: binary PATCH VisitCollection('00163EA729061EEBBDCC99E1FFDDC890') HTTP/1.1 // Define the type of request first -> Here: PATCH // Define the collection secondly -> Here: VisitCollection // Provide the ObjectID of the Object you want to update // End with HTTP/1.1 sap-context-accept: header Content-Type: application/json Accept: application/json // JSON input for updating a visit: { "Subject" : "Update Visit", "MainAccountPartyID" : "1229342", "Status" : "2" } // End of changeset_C02 --changeset_C02— // End of batch: --batch_B01--
The Customer Experience team at Camelot ITLab deals with exciting and challenging CRM related topics every day and serves a large portfolio of different customers from a wide range of industries. Trust in this collaboration and feel free to contact us at tlil@camelot-itlab.com.
Was this article helpful?
If you like our content we would highly appreciate your review on Trustpilot
#SAP C4C #SAP Cloud 4 Customer #Cloud 4 Customer #Cloud for Customer #SAP Sales Cloud #Sales Cloud #OData #API #Request #Postman #PATCHRequest #Patch