Skip to Content
Technical Articles

How to create Service Request and its Item details using Deep Insert in SAP Cloud For Customer

Overview:

In this blog post, we are going to see how to create Service Request and its Item details ( Item, Attachments, Involved Parties) using the Odata function Deep Insert in SAP Cloud for Customer system.

Answers to expect from this post?

  1. How to use Deep Insert in Odata Service Explorer
  2. What is the format we need to follow in a Deep Insert Payload

Let’s get started:

Step 1 :

Log in to your SAP Cloud for Customer System.

Go to Administrator Work center -> OData Service Explorer.

Select the Service c4codataapi and Click Test.

 

Odata%20Service%20Explorer

In the Odata Console, Choose ServiceRequestCollection among the list of Entity Sets.

As you can see, the Service Request Collection is associated with Multiple Child Entities like ServiceRequestAttachmentFolder, ServiceRequestItem, etc.

Step 2 – Creating the Payload :

Navigate to the Tab Test.

 

In the Request Method, Choose Deep Insert and choose the Payload format as JSON.

 

By using Deep Insert, We can create Parent (ServiceRequest) and Items ( ServiceRequestItem , ServiceRequestAttachmentFolder) in one call instead of multiple POST calls for Parent and Child entities.

In the Payload, The name of the child entities needs to be given followed by its data. For Parent Entity ServiceRequest, We are passing only the field “Name”, since this field is enough to create a Service Request in C4C.

Payload Example :

{     
      "Name" : "Test",
       "ServiceRequestItem":
        [{ 
        "ProductID" : "10001092"
        }],

      "ServiceRequestParty":
        [{
       "PartyID" : "10332",
       "RoleCategoryCode" : "10",
       "RoleCode" : "10",
       "Main" : true
        }],

       "ServiceRequestAttachmentFolder":
        [{
      "TypeCode":"10001",
      "MimeType":"text/plain",
      "Binary":"VGVzdCBBdHRhY2htZW50",
      "Name":"Test.txt",
      "CategoryCode":"2"
        
        }]
}

Once you execute the above Payload, you will get a success message,which means the record was created in the system.

 

Response :

As we can see from the response below, a new Service Request with ID 11192 got created.

Step 3 – Check the Data in the system :

Go to Tickets Work center and search for the Service Request ID, Which you got in the Response.

Attachments :

 

Involved Parties :

 

Items :

 

Conclusion:

  1. Commas and brackets are used to separate the entities in the Payload. Double-check the syntax, since missing a single comma will result in an error.
  2. You can also post records from an external application like Postman. But, you have to request x-csrf token to post records. Since the method Deep Insert is not available in Postman Tool, You have to use POST with the same payload.
4 Comments
You must be Logged on to comment or reply to a post.
  • Hi Palani,

    Thanks for sharing this very nice method. I have an additional question regarding using DEEPINSERT method from external system.

    I tried your payload with POST method and it worked fine and I was able to create a ticket with Product and party etc. However when I use the same payload with “DEEPINSERT”(custom method in postman) then it throws an error “Your browser sent a request that this server could not understand.”. Snapshot attached:

    Does this mean HTTP method DEEPINSERT is only working from odata console and not from outside world? i.e. can it not be used from other clients like Postman or Insomnia OR from project point of view CPI and we need to always make POST call from external clients to make this work?

    /