The CreatorCon Call for Content is officially open! Get started here.

File content corrupted when sending attachments using RESTMessageV2 API

n_stauffer
Kilo Contributor

I am trying to send attachments from ServiceNow to a third party application using the RestMessageV2 API.   The POST request is successful but the binary attachment data appears to be corrupted when it's delivered to the third party application for files like pdf, jpg, etc...   I can send pure text files without issue.   The corruption only occurs when sending from ServiceNow.   I can send the same request with postman without any issues.   Unfortunately, base64 is not supported by the third party application so it must be binary.

Here is an example of the POST request I built in ServiceNow:

HTTP Headers:

Content-Type: multipart/form-data; boundary=93a1d467-2dr3-9872-a65b-1d2f645d1c36
Cache-Control: no-cache

Body/Content:

--93a1d467-2dr3-9872-a65b-1d2f645d1c36

Content-Type: application/bin

Content-Disposition: form-data; name=bin; filename="test.jpg"; filename*=utf-8''test.jpg

${file}

--93a1d467-2dr3-9872-a65b-1d2f645d1c36--

For simplicity, right now I am using the Attachment API (doc here) to retrieve the binary data and populate the ${file} parameter.   I have tried the setRequestBodyFromAttachment method but I need to build a multi-part message so that won't work.   If you have any ideas or direction, I would greatly appreciate your feedback!

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nicholas,



Are you sending the base64encoded data for the attachment to the third party application?



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


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

Thank you for your reply.   I am trying to send binary data.   Base64 is not supported by the third party application.


I have the exact same problem - were you able to find a way to fix this?


chris_snc_
ServiceNow Employee
ServiceNow Employee