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

Revanth4
Tera Expert

Hi @n_stauffer  

 

I'm also facing same issue did you get any solution for this. If yes Please share that with me here!