Post request with a file as body

Daniel Vieira
Tera Guru

Hello

 

I am trying to upload a file to an external API (UKG/PeopleDoc) using RESTMessageV2 inside the Human Resources scope. In Postman the request works using multipart/form-data with a field named file.

In ServiceNow, I can read the attachment using GlideSysAttachment, but since getBytes() is not available in HR scope, I am reading the InputStream and building the multipart body manually. However, the external API keeps returning:

 

  • unsupported_media_type:"application/pdf" ( or others kind of same errors like this one)

My code:

 

var token = inputs.token;
var attachmentSysId = '4947443dc3227a109e8d5e3ed4013147';
var r = new sn_ws.RESTMessageV2('NAME, NAME METHOD');
 r.setRequestHeader('Authorization', 'Bearer ' + token); 
 r.setRequestBodyFromAttachment(attachmentSysId);
var response = r.execute();
gs.info('Status: ' + response.getStatusCode()); gs.info('Response: ' + response.getBody());

I'm using Flow Designer and token is right.
Does anyone knows how to read a file from attachment table and send to external api? Or how to solve this issue?
 
Thanks,
Daniel Vieira

 

 

0 REPLIES 0