wierd error when testing Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 08:49 AM
Dear all,
I have a service now dev instance where I try to test scripted Rest API feature.
The idea is to create an Incident from that REST endpoint
I have a weird error as soon as I enter some scripting in the REST API, even a simple script
The error is as below:
{"error":{"message":"Unexpected token: o","detail":"SyntaxError: Unexpected token: o (sys_script_include.d2426c9ec0a8016501958bf2ac79c775.script; line 155)"},"status":"failure"
This error occurs as long I place a single line of script as below :
var requestBody = request.body.data;
var parsedBody = JSON.parse(requestBody);
if sounds like the script cannot be interpreted at all
Any idea what could it be?
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:46 AM
It means the request.body.data
contains something unexpected, such as a string that doesn't conform to JSON format.
Try this
var requestBody = request.body.data;
gs.info('Received data: ' + requestBody);
Tell me the output
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:58 AM
Hello,
If I enter in my script section just the 2 lines of code you mention.
Then the response is return OK, but could not see the log.info result