how to get the value from requestBody in scripted rest api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 10:09 AM
how to get the value from requestBody in scripted rest api
Request Body in JSON:-
"RequestedFor": "Test.com",
"Status": "New",
"References": [
{
"DeltaId": "Test ID",
"DeltaModel": "Test Model",
"Region": "US",
}
]
Unable to fetch DeltaID and Delta Model
Even though getting the data in logs using gsinfo on refobj with below scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 12:40 PM
gs.info(refobj);//It is working and providing DeltaId
If is is working then you have DeltaId available in your variable.
Must be a issue with task script, show task script here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 01:08 PM
Hello!
From my brief testing, this has successfully returned the "DeltaId" value based on the JSON provided:
var deltaIdStr = request.body.data.References[0].DeltaId;
However, I should point out that the comma (",") after "Region": "US" in your request body should be removed.
Also, since gs.info(refobj); is returning the proper value, this likely indicates an issue with updating your Catalog Task. Can you provide your script for the REST Resource on you custom API? Which HTTP method are you using? Are you creating the task or just updating? I'm assuming ACLs aren't the issue since it appears your script is successfully executing the gs.info() line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 02:45 PM
I am both inserting and updating the data in sc_tasks. we are using Post Method for Scripted Rest API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 05:35 PM
Ah okay. Keep in mind that if you are updating records you will need to use Put instead of Post, as Post will insert new records only.
Can you sure your script for your Post method? It seems your script is successfully pulling the correct value from JSON body, so my guess the issue is with your update to the sc_task table.