- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2023 11:12 PM
I have a scripted REST api and now I am trying to get the payload if it is a valid then I am able to get it as below
var payload = request.body.data;
But if third party system send invalid JSON to ServiceNow then how to capture that I have tried different ways but not able to get it.
Below is the example of invalid JSON but I am trying to get it.
{
"Data": {
"Name": "test",
"ID": "1500"
"description": "Test description"
}
}
Share any solution if it is possible to get in any way.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 03:16 AM
Hi @Pavan_Snow_1 ,
sorry i misunderstand your question. So when i tested Scripted Rest API using Postman i got below error
"detail": "SyntaxError: Missing comma in object literal (sys_script_include.d2426c9ec0a8016501958bf2ac79c775.script; line 155)"
so you can try to open Script Include with above sys_id and in initialize function try to add gs.log(this); i'm not tested it but it may work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 02:55 AM - edited 04-16-2023 02:56 AM
try this
var res = request.body.data;
var res1= JSON.stringfy(res)
gs.log('the invalid response ' +res1)
Check system logs if the invalid payload getting captured.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 03:02 AM
Hi @Prabu Velayutha ,
Tried but not getting invalid JSON.
looks like we can't get invalid payload to ServiceNow and only receive when it is valid one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:16 AM
I think we can't get the invalid JSON as payload on request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:22 AM
I have seen you marked my response helpful,
I have answered your question correctly which you made conclusion in the end , you can accept my solution too as you can accept multiple solutions on a single post.