Multipart request to 3rd party

Parvathy B1
Tera Contributor

I have a requirement to send a multipart request having an input Json and input file. The input file is a compressed zip file in ServiceNow and expectation at third party is to have type string and binary format for the file as in screenshot. Also, the testing from Postman is successful as it allows a direct upload of the file from system. Is this feasible from ServiceNow and will the file content have any issue being compressed zip file?

Please help with the script/approach for this if feasible

3 REPLIES 3

Shivalika
Mega Sage

Hello @Parvathy B1 

 

You can use below code to send attachment in binary format - 

 

var sa = new GlideSysAttachment();
                var StringUtil = new GlideStringUtil();
                //Get the base64 encoding of the attachment
                var binData = sa.getBytes(singleattachmentsysid);
                var encData = GlideStringUtil.base64Encode(binData);

 

Now for multiple just add loop. 

 

i hope this answers your queries. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Shivalika
Mega Sage

hello @Parvathy B1 

 

I had also explored "Attachment API" in REST API explorer few days back and it does return the "binary format precisely"

 

Refer screenshot - 

 

Shivalika_0-1744179547457.png

 

Shivalika_1-1744179562744.png

 

 

You can use this as well for exact. 

 

This is a demonstration video on Attachment API - https://youtu.be/VqCxt1vSvIE?si=-3dfGQ71OLFpMYMJ

 

In case that helps. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Parvathy B1 

handling sending of multi-part is somewhat complex

check these links

Multipart/form-data attachment pusg using Rest API from Snow->Jira 

Outbound REST - Multipart/form-data 

REST API attachments Transfer to JIRA 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader