-1

I am trying to fetch Salesforce attachment body using standard REST API /services/data/v50.0/sobjects/Attachment/<record-id>/body from an external tool. This API call returns me the data in below format which seems to be application/octetstream (as read in postman content-type response header).

enter image description here

Once this data is fetched, I need to use the same file and attach it to another record in Salesforce. However, while using the standard REST API to create an attachment record,it expects the data in base64 format. What is the way by which I can convert this incoming data into base64 format and then upload attachment to another record? Or is there any other way by which I can fetch the data in a different format itself?

1 Answer 1

0

REST API will give you Binary data. If you want the File as base64 you need to make it a SOAP API request.

POST request to https:///services/Soap/c/53.0/

Headers:

Content-Type: text/xml; charset=UTF-8
Accept: text/xml
SOAPAction: ''

with payload like :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>XXXXXXXXXXXXXXXXXXXXXXX</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>SELECT Body FROM Attachment WHERE Id = '00P7A000006V8JvUAK'</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

You will receive the Output as below.

enter image description here

1
  • Thanks Saroj for your response! As I am doing this callout from a non-coding platform (ETL Workflow tool). It will be complicated to parse the content from XML and use it. Isn't there anyway we can use REST and convert the binary octet-stream into base64? The data is octet-stream as it's a Word document file Jan 31, 2022 at 16:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .