setRequestBodyFromAttachment - How does it work?

snowenthusiast
Tera Contributor

Hi everyone,

I want to know that how does setRequestBodyFromAttachment method works? I know how to use it but I just want to know what actually happens at the backend?

var request = new sn_ws.RESTMessageV2();

request.setHttpMethod('post');

request.setEndpoint('http://myendpoint');

request.setRequestBodyFromAttachment('attachment-GUID');

request.setMIDServer('my_mid_server');

var response = request.execute();

var httpResponseStatus = response.getStatusCode();

so when I fire the above code, MID server will pick it up, fetch the attachment and POST it to the endpoint.

My question is - how does that POST happens?

  • Is it using base64 encoding?
  • Or file is streamed to the endpoint?
  • Or is it sent as a multiform data content?
  • Or something else happens?

Thanks in advance.

4 REPLIES 4

snowenthusiast
Tera Contributor

Hi all - anyone with any inputs please?


Hi there,



setRequestBodyFromAttachment :- sends base 64 encoded file. So your parameter should be a encoded file.



Hope this helps


ricgupta
Kilo Contributor

Hi,



I am looking for the same requirement where I have to pass the attachment from Servicenow to Jira. Can you please help with the complete code?



Thank You,


Richa


Vivek Verma
Mega Sage
Mega Sage

Hi,

 

here is the detailed solution for this thread,

 

 

Sending attachments   (ServiceNow to 3rd party)

1. Outbound Rest message- Need to ask for an endpoint of the 3rd party. Configure HTTP headers If any.

2. Use this Rest message in the business rule to send attachments

                  a. Call the rest message and simply send the binary content of the attachment to the request body using function request.setRequestBodyFromAttachment('<attachment sys_id>');

(RESTMessageV2 - setRequestBodyFromAttachment(String attachmentSysId)   )

 

 

find_real_file.png

  Screenshot of the business rule

 

 

Please Marked this question as the answered to close the thread.

 

Regards,

Vivek