upload pdf from servicenow to Third party application

AnnalakshmiS
Tera Contributor

I'm having trouble sending an attachment. Despite setting the attachment format to multipart/form-data, I still can't get it to work. Could you please briefly guide me on this?

 

Content-Type: multipart/form-data; boundary=test

--test
Content-Disposition: form-data; name="object"
Content-Type: application/json
 
--test
Content-Disposition: form-data; name="content"; filename="{{fileName}}"
Content-Type: application/pdf

< example.pdf
--test--
2 REPLIES 2

Ankur Bawiskar
Tera Patron

@AnnalakshmiS 

check below 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 as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

IbrarA
Kilo Sage

Hi @AnnalakshmiS 

The reason that body never works is that RESTMessageV2 doesn't support multipart at all. ServiceNow's own docs list "Multipart with attachments" under what the scripted API can't do, and point you at the REST Step in IntegrationHub instead.

https://www.servicenow.com/docs/r/eJIqiaxRKVcMaR8XQU6_oA/XoVTqjPElFt41649_Vslfw

Also, the < example.pdf line in your body is curl syntax. It gets sent as those literal characters, so the PDF never goes anywhere.

If the endpoint accepts a plain binary POST, setRequestBodyFromAttachment(attachmentSysId) does the job with the content type set from the attachment. If it insists on multipart, use the REST Step, or build the body yourself with GlideSysAttachmentInputStream and a ByteArrayOutputStream.

 

Thanks

ibrar