"Exception while reading request","detail":"The payload is not valid JSON."},

Abhishek66
Tera Contributor

I am working on  Post REST Integration for Incident table   and  written below Business Rule but while i am checking the logs its showing error.

Please help to fix the error.

***********************************************************************************************************************************

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here

var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev64283.service-now.com/api/now/table/incident');
request.setHttpMethod('POST');

//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'Integration_user';
var password = 'test@1234';

request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"short_description\":\"" + current.short_description + "\"\"caller_id\":\"" + current.caller_id + "\"\"priority\":\""+current.priority + "\"\"category\":\""+ current.category
+"\" }");

var response = request.execute();
current.work_notes = response.getBody();
current.update();

//gs.log(response.getBody());

6 REPLIES 6

Community Alums
Not applicable

Try it with moving the payload away:

var payload = {"short_description":  current.short_description ,"caller_id": current.caller_id ,"priority":current.priority ,"category": current.category };

request.setRequestBody(JSON.stringify(payload));

 

P.S. You forgot the commas in your object

this is not returning the required field values.

 

 

 

Abhishek66
Tera Contributor

if i am adding commas on the required places its still not working.

below is the error.

 

 

{"error":{"message":"Exception while reading request","detail":"The payload is not valid JSON."},"status":"failure"}

Community Alums
Not applicable

Have you tested with moving it away ?

var payload = {"short_description":  current.short_description ,"caller_id": current.caller_id ,"priority":current.priority ,"category": current.category };

request.setRequestBody(JSON.stringify(payload));