wierd error when testing Scripted REST API

User687957
Mega Guru

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

6 REPLIES 6

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 

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