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

 

    1. What all are the Pre-requisites needs to be done before making a batch call.

 

    1. What is the format we need to follow in a batch Payload.

 

    1. 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.

 

    1. You are opening the Payload with –batch and it should be closed with –batch—

 

    1. The Changeset needs to be used only if you are changing the data in the database using POST, PATCH, PUT.

 

  1. Changeset is not required to fetch a data from the database.
Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x