<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question setRequestBodyFromAttachment - How does it work? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472361#M129287</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14725151765116879 jive_macro_code jive_text_macro" data-renderedposition="92_8_1192_128" jivemacro_uid="_14725151765116879" modifiedtitle="true"&gt;&lt;P&gt;var request = new sn_ws.RESTMessageV2();&lt;/P&gt;&lt;P&gt;request.setHttpMethod('post');&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;request.setEndpoint('&lt;/SPAN&gt;&lt;A title="k-external-small" class="jive-link-external-small" href="http://myendpoint');" rel="nofollow" target="_blank"&gt;http://myendpoint');&lt;/A&gt;&lt;/P&gt;&lt;P&gt;request.setRequestBodyFromAttachment('attachment-GUID');&lt;/P&gt;&lt;P&gt;request.setMIDServer('my_mid_server');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var response = request.execute();&lt;/P&gt;&lt;P&gt;var httpResponseStatus = response.getStatusCode();&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so when I fire the above code, MID server will pick it up, fetch the attachment and POST it to the endpoint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is - how does that POST happens?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is it using base64 encoding?&lt;/LI&gt;&lt;LI&gt;Or file is streamed to the endpoint?&lt;/LI&gt;&lt;LI&gt;Or is it sent as a multiform data content?&lt;/LI&gt;&lt;LI&gt;Or something else happens?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Aug 2016 00:02:57 GMT</pubDate>
    <dc:creator>snowenthusiast</dc:creator>
    <dc:date>2016-08-30T00:02:57Z</dc:date>
    <item>
      <title>setRequestBodyFromAttachment - How does it work?</title>
      <link>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472361#M129287</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14725151765116879 jive_macro_code jive_text_macro" data-renderedposition="92_8_1192_128" jivemacro_uid="_14725151765116879" modifiedtitle="true"&gt;&lt;P&gt;var request = new sn_ws.RESTMessageV2();&lt;/P&gt;&lt;P&gt;request.setHttpMethod('post');&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;request.setEndpoint('&lt;/SPAN&gt;&lt;A title="k-external-small" class="jive-link-external-small" href="http://myendpoint');" rel="nofollow" target="_blank"&gt;http://myendpoint');&lt;/A&gt;&lt;/P&gt;&lt;P&gt;request.setRequestBodyFromAttachment('attachment-GUID');&lt;/P&gt;&lt;P&gt;request.setMIDServer('my_mid_server');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var response = request.execute();&lt;/P&gt;&lt;P&gt;var httpResponseStatus = response.getStatusCode();&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so when I fire the above code, MID server will pick it up, fetch the attachment and POST it to the endpoint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is - how does that POST happens?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is it using base64 encoding?&lt;/LI&gt;&lt;LI&gt;Or file is streamed to the endpoint?&lt;/LI&gt;&lt;LI&gt;Or is it sent as a multiform data content?&lt;/LI&gt;&lt;LI&gt;Or something else happens?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 00:02:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472361#M129287</guid>
      <dc:creator>snowenthusiast</dc:creator>
      <dc:date>2016-08-30T00:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: setRequestBodyFromAttachment - How does it work?</title>
      <link>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472362#M129288</link>
      <description>&lt;P&gt;Hi all - anyone with any inputs please?&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2016 17:23:53 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472362#M129288</guid>
      <dc:creator>snowenthusiast</dc:creator>
      <dc:date>2016-08-30T17:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: setRequestBodyFromAttachment - How does it work?</title>
      <link>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472363#M129289</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;setRequestBodyFromAttachment :- sends base 64 encoded file. So your parameter should be a encoded file. &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Nov 2016 14:27:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472363#M129289</guid>
      <dc:creator>Dharshini Rohit</dc:creator>
      <dc:date>2016-11-21T14:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: setRequestBodyFromAttachment - How does it work?</title>
      <link>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472364#M129290</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;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?&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Thank You,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Richa&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Apr 2017 21:40:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472364#M129290</guid>
      <dc:creator>ricgupta</dc:creator>
      <dc:date>2017-04-19T21:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: setRequestBodyFromAttachment - How does it work?</title>
      <link>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472365#M129291</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is the detailed solution for this thread,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;Sending attachments &amp;nbsp; (ServiceNow to 3rd party)&lt;/P&gt;
&lt;P class="ng-scope"&gt;1. Outbound Rest message- Need to ask for an endpoint of the 3rd party. Configure HTTP headers If any.&lt;/P&gt;
&lt;P class="ng-scope"&gt;2. Use this Rest message in the business rule to send attachments&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a. Call the rest message and simply send the binary content of the attachment to the request body using function&amp;nbsp;&lt;SPAN class="pln"&gt;request&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;setRequestBodyFromAttachment&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str"&gt;'&amp;lt;attachment sys_id&amp;gt;'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;SPAN class="pun"&gt;(&lt;A title="https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/app-store/dev_portal/API_reference/RESTMessageV2/reference/r_RMV2-setReqBodyFromAttachment_S.html" href="https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/app-store/dev_portal/API_reference/RESTMessageV2/reference/r_RMV2-setReqBodyFromAttachment_S.html" rel="nofollow"&gt;RESTMessageV2 - setRequestBodyFromAttachment(String attachmentSysId)&lt;/A&gt;&amp;nbsp;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;SPAN class="pun"&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/162706iD065339D0929AA33/image-size/large?v=v2&amp;amp;px=999" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp; Screenshot of the business rule&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;Please Marked this question as the answered to close the thread.&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;Regards,&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;A href="https://www.linkedin.com/in/vivek-verma-a655aa16a" target="_blank" rel="noopener noreferrer nofollow"&gt;Vivek&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 16:17:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/setrequestbodyfromattachment-how-does-it-work/m-p/1472365#M129291</guid>
      <dc:creator>Vivek Verma</dc:creator>
      <dc:date>2019-08-20T16:17:38Z</dc:date>
    </item>
  </channel>
</rss>

