While sending the attachment thorugh REST message getting error "500"

VIKAS MISHRA
Tera Contributor

We have setup one REST message integration from our serviocenow to 3rd party ServiceNow instacne between SC task.

So whenever we attach any attchment to our task it should sent that attachment to 3rd party task, but getting error as mentioned in below screenshot. please suggest. as its not passing the attachment.

VIKASMISHRA_0-1687862019214.png

 

1 ACCEPTED SOLUTION

Instead of using setStringParameterNoEscape() function try to create a json format. setStringParameterNoEscape() function is mostly used for formdata format of rest api request body whereas as per you requirement you need to have a raw data format in json. for that you need to try using below code to create a JSON 

 

var r = new sn_ws.RESTMessageV2('SOCIntegrationTask', 'Update Task');
        var body = '{ "application" : "' + current.u_application + '", "taskid" : "' + current.u_task_id + '", "status" : "' + stateChange + '", "targetassignmentgroup" : "' + assignmentGroup + '"}';
        r.setRequestBody(body);
        var response = r.execute();

 

You are getting HTTP 500 which means internal server error. This usually happens when server is not able to understand what needs to be execute or what unable to understand request body parameter. Therefore try the above format for request body. 

 

 

 

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@VIKAS MISHRA 

it clearly says that the json request body is not a valid one.

Did you check by adding logs how the request body looks like?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I Just put the logs and found it is having such value "SCTASK0022969 RequestBody [object RESTResponseV2]"

 

As per the design document it should be as mentioned below.

Request Body –

{"file_name":"Test",

"content_type":".png",

"ticket_number":"TASK034572",

"fileData": "my sample file"

}

@VIKAS MISHRA 

check these links

Unable to send attachment via REST 

Business rule to send attachment to 3rd Party Tool via REST 

Send attachment via rest message

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I have seen all the links provided by you, my scripts seems to be correct but not sure why for attachment passing only its not generating the correct request format