The Now Platform® Washington DC release is live. Watch now!
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.
05-22-2018 04:39 AM
Hi,
You can send data to 3rd party in multipart. Please find the below changes you need to contain:
Headers: When you configure the Rest Message function have following in your http request: In this example for multi part we need to inform what is the boundary.
Name: Value
Content-Disposition: form-data
Content-Type: multipart/form-data; boundary=-----WebKitFormBoundaryAAA
Rest other steps are fine. just ensure content type, file name and file variable you replace with proper value.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
05-22-2018 04:57 AM
Hi,
I've got all that in the header and so unfortunately this hasn't done the trick 😞
05-22-2018 06:36 AM
Ankur,
Do you have any further thoughts on this?
Latest error is:
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3778; Character reference "" is an invalid XML character.
05-22-2018 06:59 AM
Hi,
It seems some invalid character is being sent over and causing the error.
Mostly seems to be null character because  doesn't seem to be any valid character.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur