Issue with getRequestBody() in Attachment api

Kishor O
Tera Sage

Attachment api is working fine and returning 201 status code but getRequestBody() always returns null what might be the issue with this?

 

KishorO_0-1752750168530.png

 

7 REPLIES 7

Brad Warman
Giga Sage

How are you calling getRequestBody()?

 

Here's the developer doco on how to use it in a REST message - https://developer.servicenow.com/dev.do#!/reference/api/yokohama/server/sn_ws-namespace/c_RESTMessag...

 

@Brad Warman  Please find the script I am using

var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("post");
restMessage.setEndpoint("https://mytestdev.service-now.com/api/now/attachment/file");
restMessage.setBasicAuth('SN_INT_USER_IDM_User', 'CRbr#9extusrpr');
restMessage.setQueryParameter("table_name", "incident")
restMessage.setQueryParameter('file_name', 'ODOO and ServiceNow integration (AutoRecovered).docx');
restMessage.setQueryParameter('table_sys_id', '8f9a39a783e66610da0653a8beaad325')
restMessage.setRequestHeader("Content-Type", "application/json");
restMessage.setRequestHeader("Accept", "application/json");
restMessage.setRequestBodyFromAttachment("e4fd39afc366221001a098ec0501315e");
var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var requestBody = restMessage ? restMessage.getRequestBody() : null;
gs.print("status" + " " + httpStatus);
gs.log("requestbody" + " " + requestBody);
gs.print("response body" + " " + responseBody);

What is the content of the attachment? You may need to update your content-type header to match the content type of the attachment

Ankur Bawiskar
Tera Patron
Tera Patron

@Kishor O 

is the file getting sent over and attached to that record you mentioned?

If yes then it's strange.

Seems it's OOTB platform behavior.

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