Skip to Content
Technical Articles
Author's profile photo Palanikumar Subramanian

How to send a Odata Batch Request to SAP Cloud for Customer system using Postman Tool

Overview:

In this blog post,we are going to see how to send a Odata Batch Request to the SAP Cloud for Customer system using POSTMAN Tool.

Answers to expect from this post?

  1. How to use batch request in the POSTMAN Tool
  2. What all are the Pre-requisites needs to be done before making a batch call.
  3. What is the format we need to follow in a batch Payload.
  4. What all are the header details needs to be maintained.

Lets get started:

Step 1 :

Login to the Postman Tool using your credentials.

In the Authorization Tab, Enter your credentials as below:

Step 2 :

The Next step is to fetch the CSRF Token.

CSRF Token is necessary in order to update or create the records in the C4C System.

For a GET Call, you don’t need a CSRF Token.

In order to get the CSRF Token,Go to the Header Tab.

Enter ‘x-csrf-token’ in the key and ‘Fetch’ in the Value as below:

After this, you have to make a get call to the C4C System.
Choose the action as GET and enter the URL to make the GET call to C4C System.

URL :

https://myXXXXXX.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection(‘YYYYYYYYYYY’)

XXXXXX – Tenant ID
YYYYYYYYYYYYY – Object id of a particular record in the Service Request Collection.

Note: You can use any collection to get the CSRF Token.

Once the GET Call is made, Go to the Headers Tab and Copy the x-csrf-token.

Now, navigate to the Top Header Tab and Paste the CSRF Token as below:

We have completed the Pre-requisite to post a record in the system.

 

Step 3 :

Now, we are going to create 3 Service Requests in the system in a single batch call.

Choose the Action as POST and enter the URL as below:

https://myXXXXXX.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/$batch

In case of batch call, you don’t need to mention the Collection name as you will mention the collection name in the Payload.

Go the Tab Body and Choose raw.

Copy paste the below Sample Payload.

This Payload will create three Service Requests in the System. We are passing only the Name field to create a record in the system, as it is the only mandatory field to create a Service Request.

Sample Payload for creating three records in the Batch Call :

--batch
Content-Type: multipart/mixed; boundary=changeset

--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary

POST ServiceRequestCollection HTTP/1.1
Content-Type: application/json
Content-ID: 2
Content-Length: 10000

{
"Name":"Testing 1"
}

--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary

POST ServiceRequestCollection HTTP/1.1
Content-Type: application/json
Content-ID: 2
Content-Length: 10000

{
"Name":"Testing 2"
}

--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary

POST ServiceRequestCollection HTTP/1.1
Content-Type: application/json
Content-ID: 2
Content-Length: 10000

{
"Name":"Testing 3"
}

--changeset--
--batch--

It is important to maintain the content type in the Header, for the system to recognize the Payload.

 

Once you add the Payload and the Headers, Click “SEND’ to send the request to the C4C System.

The request is successful, only when you receive a response back as below:

Conclusion:

If you get any error or if you are not getting any response back, check the below points :

  1. The Payload is Space Sensitive, it is mandatory to maintain the proper spacings.
  2. You are opening the Payload with –batch and it should be closed with –batch—
  3. The Changeset needs to be used only if you are changing the data in the database using POST, PATCH, PUT.
  4. Changeset is not required to fetch a data from the database.

 

Assigned Tags

      25 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Raphael Lechner
      Raphael Lechner

      Hi Palanikumar,

      thanks for the article.

      For Step 2: Did you check the blog from Andrei Vishnevsky for autofill CSRF-Token? If you do it with the Script you never need consider the csrf token anymore as it's done via the script.

      https://blogs.sap.com/2019/08/27/csrf-token-in-postman.-one-click-to-get-it-and-use-it./

       

      Best regards,

      Raphael

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Raphael,

      Thanks for the suggestion. I will check and try to add a note.

      Regards,

      Palani.

      Author's profile photo sunny kumar
      sunny kumar

      Hi PalaniKumar,

       

      Could you please tell me how to use Patch request in $batch option.If you give an example that would be great.

       

      Regards,

      Sunny

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Sunny,

      You just have to replace POST with PATCH and then pass the desired payload. For Patch, You need to pass the Object ID. In the below example, XXXXXXXXXXXX is the Object ID.

      Example :

       

      --changeset
      Content-Type: application/http
      Content-Transfer-Encoding: binary
      
      PATCH ServiceRequestCollection('XXXXXXXXXXXXXXXXXX') HTTP/1.1
      Content-Type: application/json
      Content-ID: 2
      Content-Length: 10000
      
      {
      "Name":"Testing 2"
      }
      Author's profile photo Mohanbabu KJ
      Mohanbabu KJ

      Hello Palani,

       

      Thank you for your Post. I'm trying to have batch operation for Account which includes services CorporateAccountCollection, ObjectIdentifierMappingCollection and CorporateAccountIdentificationCollection.

       

      Here is my question post: https://answers.sap.com/questions/13114564/batch-operation-in-odata-for-account.html

       

      Can you please check and let me know what I might be doing wrong?

       

      Thanks.

       

      Regards,

      MB

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Mohan,

      CorporateAccountIdentification is a child entity of CorporateAccount. It is not possible to create data for child without using parent reference. 

      In order to achieve this in Batch, you need to send the payload in Deep Insert format instead of sending it as a separate POST.

      Sample Payload, Which worked in my system:

      --batch
      Content-Type: multipart/mixed; boundary=changeset
      
      --changeset
      Content-Type: application/http
      Content-Transfer-Encoding: binary
      
      POST CorporateAccountCollection HTTP/1.1
      Content-Type: application/json
      Content-ID: 2
      Content-Length: 10000
      
      { "Name":"Testing Batch Operation MB", 
        "RoleCode":"XXXXXX", 
        "CountryCode":"US", 
        "CorporateAccountIdentification" :
      
      [{ "IDTypeCode":"XXXXXX", "IDNumber":"9999999999" }]
      }
      
      --changeset--
      --batch--

       

      Regards,

      Palani.

      Author's profile photo Kunal Surati
      Kunal Surati

      Hello Palani, your blog is very useful. I am trying to insert multiple records with batch method from Postman tool. However, I am getting 202 Accepted in response in Post method instead of 201 Created. I followed payload syntax and it’s still the same. Do you know what am I doing wrong?

      My service name is “Fuel”. Below is the service URL.

      https://<hostname:port>/<foldername>/applications/GIRW250/service/girw250bulkfuel.xsodata/Fuel/

      and below is my Payload body:

       

      --batch
      Content-Type: multipart/mixed; boundary=changeset

      --changeset
      Content-Type: application/http
      Content-Transfer-Encoding: binary

      POST Fuel HTTP/1.1
      Content-Type: application/json
      Content-ID: 2
      Content-Length: 10000

      {
      “ID”:” ”
      }

      --changeset--
      --batch--

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Kunal,

      Kindly check whether you have maintained the content type in the Header.

      Regards,

      Palani.

      Author's profile photo Kunal Surati
      Kunal Surati

      Hi Palani, yes I am maintaining following as Content-Type header for Post method

      multipart/mixed;boundary=batch

      But now I am getting different error

      HTTP/1.1 400 Bad Request
      Content-Type: application/xml;charset=utf-8
      Content-Length: 250

      <?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code/><message xml:lang="en-US">Error processing request stream. JSON text specified is not valid.</message></error>

       

      Regards,

      Kunal

      Author's profile photo Johan de Zwart
      Johan de Zwart

      Hi Kunal,

      Did you find a solution for this?

      regards,

      Johan

      Author's profile photo Johan de Zwart
      Johan de Zwart

      I found the solution. I had the wrong boundry in the header of the request

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Kunal,

      It looks like you are passing a blank value in the field ID. Kindly make a normal POST call and check whether the record is getting created.

      Regards,

      Palani.

      Author's profile photo Kunal Surati
      Kunal Surati

      Hi Palani, Id is autogenerated sequence number from the service. Issue was missing batch format for every new POST changeset. Check below blog:

       

      https://answers.sap.com/questions/13186072/sap-hana-xsa-odata-service-post-method-for-batch-i.html

       

       

       

       

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Kunal,

      If it auto generated, You do not have to pass the ID field in the Request. But, if there is any mandatory field required to create data, you need to pass the same.

      Example :

      In the link, you have shared they are passing the below two fields, Which might be mandatory

      {"CustomerID":"456","Name":"Potter"}
      
      
      Regards,
      Palani.
      
      
      Author's profile photo Surinder g
      Surinder g

      Hi Palani,

        your blog is very fruitful. I'm trying to have batch operation to get the sales order but facing bad request error.

       

       

       

      Can you please check and let me know what I might be doing wrong in the request payload?

       

      Thanks.

       

      Regards,

      G Surinder

       

       

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Surinder,

      It looks like the issue is happening because of the filter (Salesorder= '5000122')

      You need to use the filter similar to the normal GET call.

      SalesOrder?$filter=Salesorder eq '5000122'

      Regards,

      Palani

      Author's profile photo BW SSC-BIN
      BW SSC-BIN

      Hi Palani,

       

      We are following this approach to 'POST' batch data into HANA XSA table and it is successful.

       

      However, the data is inserted record by record into the  HANA Table instead of all records at once. Is there any way to fix this?

       

      Please note that we are doing batch load via postman. We post a batch of 600 records.

       

      regards,

      Praveen

      Author's profile photo Dhruvin Mehta
      Dhruvin Mehta

      Thanks for the nice explanation, How do it send multiple "GET" calls in a batch for example calling below two services in batch and retriving response in one?

      https://my3xxxxxx.crm.ondemand.com/sap/c4c/odata/ana_businessanalytics_analytics.svc/RPZ9E2D149D2B3B6224C25C8EQueryResults?$select=CDOC_ID,TDOC_ID,FCKF_DSF_EXPCTSRTDT&$filter=(CDPY_MAINPROSPCT eq '1009227') and (CDPC_CONTACT_UUID eq '1009228')
      and (CDPY_PARTY_UUID eq '8000000387')&$top=100000&$format=json

      https://my3xxxxxx.crm.ondemand.com/sap/c4c/odata/ana_businessanalytics_analytics.svc/RPZ9E2D149D2B3B6224C25C8EQueryResults?$select=CDOC_ID,TDOC_ID,FCKF_DSF_EXPCTSRTDT&$filter=(CDPY_MAINPROSPCT eq '1009227') and (CDPC_CONTACT_UUID eq '1009229')
      and (CDPY_PARTY_UUID eq '8000000387')&$top=100000&$format=json

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Mehta,

      This is a business analytics Odata call. I could not see any particular entity name in this URL.

      In case of batch, you need to pass the URL and the collection name(along with filters) separately as mentioned above.

      Regards,

      Palani.

      Author's profile photo Dhruvin Mehta
      Dhruvin Mehta

      Hi,

      Can u please explain with an example please?

      BR

      Dhruvin

      Author's profile photo Hua Liu
      Hua Liu

      Hi Palanikumar,

      thanks for the article.

      can you tell me how to batch call custom BO,

      I get error "The server is refusing to process the request because the entity has an unsupported format" when calling custom OData.

      Regards,

      L

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      Hi Liu,

      The rules for custom and standard Odata is same. Make sure you pass the correct URL and the payload.

      https://myXXXXX.crm.ondemand.com/sap/c4c/odata/cust/v1/XXXXXXXX/$batch

      POST "pass your collection name here" HTTP/1.1
      Content-Type: application/json
      Content-ID: 2
      Content-Length: 10000

      Author's profile photo Palanikumar Subramanian
      Palanikumar Subramanian
      Blog Post Author

      The rules for Custom and Standard Odata is same.

      Make sure you pass the correct URL and collection name.

      URL :

      https://myXXXXX.crm.ondemand.com/sap/c4c/odata/cust/v1/XXXXXXXX/$batch

      POST "your collection name " HTTP/1.1
      Content-Type: application/json
      Content-ID: 2
      Content-Length: 10000

      Regards,

      Palani.

      Author's profile photo Bastian Danielzik
      Bastian Danielzik

      Hi Palanikumar,

      thanks for the helpful article.

      I am using the SAP Cloud Integration´s OData Adapter to make to batch call towards C4C. According to C4C OData monitor the batch call is successfull, however I get an error message in the Cloud Integration when for the response message of C4C (com.sap.gateway.core.ip.component.odata.exception.OsciException: org.apache.olingo.odata2.api.ep.EntityProviderException.ILLEGAL_ARGUMENT [results]null in EntitySet CommunicationTypePermissionCollectionIllegal argument for method call with message 'results'.)

      Did you already used the OData Adapters batch functionality in combination with the C4C oData API and came arround this issue?

      SAP help post:

      https://answers.sap.com/questions/13820777/entityproviderexceptionillegal-argument-when-using.html

      Regards
      Bastian

      Author's profile photo Sanket Jain
      Sanket Jain

      Hi Palani,

       

      I am trying to update the Service request header using a batch call, as well as trying to create a record at item level.

      I have implemented various suggestions as suggested in the blog and comments but nothing worked out.

      I am using below payload, which is returning status 202, but actually not doing anything in the system.

      Earlier i tried with a collection of Patch and POST within the same call; that didn't work out.

      Below deep insert option i tried as well, that is not working out.

      Maintained this in the header:multipart/mixed;boundary=batch

      --batch
      Content-Type: multipart/mixed; boundary=changeset
      --changeset
      Content-Type: application/http
      Content-Transfer-Encoding: binary
      PATCH ServiceRequestCollection('XXXXXXXXXXXXXXXXXXXXXXXXXXXX') HTTP/1.1
      Content-Type: application/json
      Content-ID: 2
      Content-Length: 10000
      {"Test_boolean_KUT":false,"ServiceRequestItem":[{"ProductID":"XXXX","ActualQuantity":"1","UserServiceTransactionProcessingTypeCode":"Z1","ServiceRequestExecutionLifeCycleStatusCode":"1"}]}
      --changeset1--
      --batch--

       

      Any help/ pointers would be much appreciated.

       

      Thanks and Regards

      Sanket Jain