Outbound REST - Multipart/form-data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2018 12:54 AM
Hi,
Currently working on an outbound REST to 3rd party tool (through a mid server). 3rd party requires mutipart to be sent when sending a file to attach/upload.
Test the POST call on postman and all ok. When in servericenow I'm getting no-where quick 🙂
That said I can get some kind of response just not the one I want (i.e. file uploaded). See REST content:
-----WebKitFormBoundaryAAA
Content-Disposition: form-data; name="file"; filename=${filename};
Content-Type:${contenttype}
${file}
-----WebKitFormBoundaryAAA
${contenttype} comes from the content type of the attachment on the sys_attachment table and ${file} is created using the below (which is in a script include):
-----------------------------------------------------------------------------------
var grAtt = new GlideRecord('sys_attachment');
grAtt.addQuery('table_sys_id', sys_id of attachment);
grAtt.query();
if(grAtt.next()){
var gsa = GlideSysAttachmentInputStream(grAtt.sys_id.toString());
var bytesContent = new Packages.java.io.ByteArrayOutputStream();
gsa.writeTo(bytesContent);
bytesContent.close();
//Get the file content
var mycontentStr = new Packages.java.lang.String(bytesContent.toByteArray());
i then set mycontentStr as a parameter to pass to the rest call.
Any help would be appreciated!...ive scoured the community and read a few things that multipart not supported and to use MId server script include however there seems to be conflicting views on this.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 06:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 07:47 AM
Hi,
I would encourage avoid asking secondary question to same post and also since this is older post.
It's better to create a second post so there's a separation in the questions being asked.
please post a question and share the link
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 08:30 PM
Hi Ankur,
Apologies.
Below is the link to the post:
https://community.servicenow.com/community?id=community_question&sys_id=77ce7c9bdb9f54104aa5d9d9689619ee
Please have a look.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2018 12:57 PM
I was facing the same issue, got HI team on this and servicenow DOES accepts form-data format, although it wont accept files to be attached (unless you are on LONDON and the Integration Hub plugin needs to be purchased ($$$$), and it will be available ONLY on "Flow Designer" where you could use the "file" form-data as postman does, but instead of using "upload file" it will use the sevicenow sys_id's under sys_attachment_list.do).
Try this:
var r = new sn_ws.RESTMessageV2('<12312312312321>', 'POST');
var var1 = "test1";
var var2 = "test2";
var var3 = "test3";
r.setStringParameterNoEscape('form1', var1);
r.setStringParameterNoEscape('form2', var2);
r.setStringParameterNoEscape('form3', var3);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
Please mark as this as helpful if it was.
Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 07:04 AM
Hi,
Multipart/form-data requests are now supported via the REST action step in the IntegrationHub which comes as part of the ServiceNow IntegrationHub Installer plugin available for a fee in the Madrid release.
The procedure to set this up is explained in the below knowledge article.
How to send Outbound REST request with multipart/form-data
Regards,
Prabhat