4

I am trying to pull in an attachment from a case in salesforce to a separate web application. I am able to get the ContentDocument properties but not the actual binary.

Here is the endpoint I am using now to get the properties.

/services/data/v41.0/sobjects/ContentDocument/0690n000000A1a1AAC

I saw in older posts that when this was stored in the attachments object you could just as /body at the end. That doesn't work for the ContentDocument.

Any direction to documentation would be appreciated.

4
  • pretty sure you have to fetch the contentVersion for that
    – glls
    Mar 22, 2018 at 18:27
  • @glls and that object connects to the contentDocument I am assuming. I'll take a look at that.
    – Crash667
    Mar 22, 2018 at 18:35
  • indeed, via ContentDocumentId
    – glls
    Mar 22, 2018 at 18:36
  • @glls That looks to be it. Then its the VersionData part of the object? I see a contentBodyId? Also if you put that as an answer, I will accept it. Otherwise I will add the answer myself.
    – Crash667
    Mar 22, 2018 at 18:43

2 Answers 2

5

To get the the raw data of the document, you actually need to query ContentVersion, which is related via the ContentDocumentId.

From there, you can access the VersionData field (amongst others)

1
  • i tried accessing services/data/v46.0/sobjects/contentversion/id from external service. It is returning invalid session id.
    – 7'7'
    Nov 15, 2019 at 13:07
3

You got close in your comment to retreiving the file, but if you're going to make a GET request to download it via the API, you need to specify the VersionData at the end of the URL, like so:

/services/data/v47.0/sobjects/ContentVersion/{{Id}}/VersionData

You must log in to answer this question.

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