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?
- How to use Deep Insert in Odata Service Explorer
- 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.
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.
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:
- 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.
- 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.
Nice blog!!
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?
Deep insert is nothing but POST method. Here it is explicitly mentioned. https://github.com/SAP/C4CODATAAPIDEVGUIDE#supported-http-operations
Hi Saurabh,
It looks like, the custom method which you have created is not compatible with C4C. In C4C,Deep Insert is a standard method which comes with OData Console. This is the reason, it works in OData Console. So, it is better to use POST from non SAP applications, since standard methods like POST, GET, PATCH,PUT are compatible with C4C.
Hi,
Thanks for sharing this blog.
Using your method, I tried the payload using the DEEPINSERT method about InstallBase.
It worked not fine and I wasn't able to create a "InstalledBase" and "InstalledBaseDescription".
Error message:The Data Services Request could not be understood due to malformed syntax|Error while parsing an XML stream: 'BOM / charset detection failed'.
Does this mean the follow input contents of json is incorrect ?
-JSON Payload-

-Error-
Best Regards.
Yuuki
Hi Yuuki,
It looks like an error in the format. There is no data given for Installed Description field.
Regards,
Palani.
Hi Palani,
Thank you for your replay.
I tried again and it worked fine.
Once an error occurs, the error will be displayed many times even if it is corrected thereafter.
However, when I restarted Odata Service Explorer, the error disappeared.
Best regards,
Yuuki
Hi Palani,
Do we have Deep Update/Upsert option to perform similar to Deep Insert.?
Is there any way to achieve the deep update?
Thanks,
GK.