How to set correct request using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:13 AM
Hi Everyone,
I'm getting below error while calling api.
Error: Response body{"statusCode":400,"titleMessage":"Bad Request","helpMessage":"Please correct the input object","userMessage":"There was an error while processing JSON content"}
Code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 03:42 AM
Hi,
I have followed the same as above, still getting the same error. Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 05:48 AM
It would help if you posted exactly what you tried.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 09:13 AM
Hi,
I'm sending below request to 3rd party application.
var requestBody = {
"taskIds": [
collibra_id
],
"formProperties": {
"success": approvalStatus1,
"failure": approvalStatus2
}
};
Everything is good, but issue here is "taskIds": [
collibra_id
], getting 400 bad request because of this when i given value of collibra_id directly in double quotation marks it is working fine im getting correct response when i given dynamic value like collibra_id change depends up on value from catalog form. When i printed request body in the logs it is showing as empty.
{"taskIds":[{}],"formProperties":{"success":"false","failure":"true"}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 09:25 AM - edited 11-02-2023 04:02 PM
What you write makes me to believe that you define variable collibra_id as you originally did (
var collibra_id = current.variables.colib_task_id;
) not following @Shruti 's advice (
var collibra_id = current.variables.colib_task_id.toString();
).
In ServiceNow fields (on GlideRecords, e.g. current.number) and variables (e.g. current.variables.colib_task_id) are NOT primitive values (like "A", 2, false), but objects.
Thus when coerced to string - like when they are (JSON) stringified, those end up as "{}" INSTEAD OF "A", "2" or "false" - even if in the database you will find those values ("A", 2 or false).
That is why when you need to get the actual value in a field or variable (JSON) stringif objects that contain values from fields or variables you should force their first convert those into string - exactly what and how @Shruti suggested.