setRequestBodyFromAttachment results in response "post request body is missing content"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2019 12:43 AM
Hi community,
I am using rest message to post attachments to 3rd party tool, Im using setRequestbodyfromattachment(attacment_sysId);
but ECC queue is returning "post request body is missing content" error.If I use base64 code as a body it is working fine but not setRequestbodyfromattachment. I have given admin access to mid server.
script is like
var myInput = 'filename.txt';
var myProfile = new GlideRecord('sys_auth_profile'); myProfile.get('name',
gs.getProperty('system.property.authProfile'));
var myAttachment = new GlideRecord('sys_attachment');
myAttachment.get('file_name',myInput);
var myEndPoint = gs.getProperty('system.property.endpoint');
var requestBody; var responseBody; var status; var sm;
try{
sm = new sn_ws.RESTMessageV2("RESTmsg", "RESTmethod");
sm.setAuthenticationProfile('basic', myProfile.sys_id);
sm.setEndpoint(myEndPoint);
sm.setRequestHeader('Accept', 'application/json');
sm.setRequestHeader('Content-Type', myAttachment.content_type); sm.setRequestBodyFromAttachment(myAttachment.sys_id);
sm.setHttpTimeout(10000);
response = sm.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode(); }
catch(ex) {
responseBody = ex.getMessage();
status = '500'; }
finally {
requestBody = sm ? sm.getRequestBody():null; }
if(status == '200' || status == '201')
{ gs.log("callExternal.sendPOST: Status Code: " + status);
gs.log("callExternal.sendPOST: Request Body: " + requestBody);
gs.log("callExternal.sendPOST: Response: " + responseBody); output = 'PASS'; }
else { gs.log("callExternal.sendPOST: Status Code: " + status);
gs.log("callExternal.sendPOST: Request Body: " + requestBody);
gs.log("callExternal.sendPOST: Response: " + responseBody); output = 'FAIL'; } }
else { output = 'FAIL'; }
- Labels:
-
Orchestration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 04:37 AM
Hi Raju,
Can you try to give contenttype in the rest message as either application/json etc and check once because the content type you are setting is from sys_attachment table which is not the expected value in that http header
sm.setRequestHeader('Content-Type', 'application/json');
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader