How to send pdf files as a binary data in attachment api

Sneha39
Mega Guru

Hi ,

I have create attachment API but PDF file is getting corrupted when send through API.

1. How can I send pdf file in binary format ?

Thanks in advance

3 REPLIES 3

jarodm
Mega Guru

My response in a previous question (post: Re: Business rule to send attachment to 3rd Party Tool via REST )



The easiest way is to use the RestMessageV2 in your script and use setRequestBodyFromAttachment(). It will put the binary of the attachment into your request body, no converting needed.



Docs: RESTMessageV2 - setRequestBodyFromAttachment(String attachmentSysId)


Hi   Jarod,



Thanks so much for your reply.



Can you please let me know how can send attachment in raw data.



for eg I am using below to send create incident :


[


{


"req_short_description":"test5",


"req_user_name":"fdudon",


"attachment" : [


          {


"req_content_type":"plain/text",


              "req_binary_input":"YWJjZA==",


"req_file_name":"tp12.txt"


          },


          {


"req_content_type":"plain/text",


"req_binary_input":"bmxqZGc=",


"req_file_name":"tp21.txt"


          }


          ]


}


]



Thanks


sachin_namjoshi
Kilo Patron
Kilo Patron

Please refer below post which has solution to your question.



Sending a pdf to the Rest API with javascript



Regards,


Sachin