Using the API How can i get “file” attachment. I am able to get “attachment” correctly

attachmentcontentdocumentcontentdocumentlink

I am able to list and download any item that the Type=Attachment with no issue.

I can get a list of items where the Type=File.
How can I Download the items that are Files? I am using Salesforce Classic.

My SOQL query to get all files (where LinkedEntityId is the opportunity):

  /services/data/v40.0/query/?q=SELECT+ContentDocumentId+FROM+ContentDocumentLink+WHERE+LinkedEntityId='0066f000018z4Fb'

the result:

stdClass Object
(
[totalSize] => 3
[done] => 1
[records] => Array
    (
        [0] => stdClass Object
            (
                [attributes] => stdClass Object
                    (
                        [type] => ContentDocumentLink
                        [url] => /services/data/v40.0/sobjects/ContentDocumentLink/06A6f00000MEMwkEAH
                    )

                [ContentDocumentId] => 0696f00000FfoNEAAZ
            )
.......

so then:

"/services/data/v40.0/sobjects/ContentVersion/0696f00000FfoNEAAZ/VersionData";

and the result:

[{"errorCode":"NOT_FOUND","message":"The requested resource does not exist"}]1

enter image description here

I am trying to download Items 1,2, and 4

After trying what you mentioned:

/services/data/v40.0/query/?q=SELECT+Id,ContentDocumentId+FROM+ContentVersion+WHERE+ContentDocumentId='06A6f00000MEMwkEAH'
stdClass Object
(
[totalSize] => 0
[done] => 1
[records] => Array
    (
    )

)

Best Answer

How can I Download the items that are Files? I am using Salesforce Classic.

Since you are using REST API to fetch data, it doesn't matter whether you are using Salesforce classic or lightning. Its the data that you pass in the callout that matters.

You are trying to use ContentDocument ID to retrieve record from ContentVersion object, hence the error.

/services/data/v55.0/query/?q=Select+Id,ContentDocumentId+from+ContentVersion+where+ContentDocumentId='<Content Document ID goes here>'

You should probably make an additional callout to the above endpoint to fetch the content version ID and use it in the endpoint mentioned below:

/services/data/v40.0/sobjects/ContentVersion/<Content Version ID goes here>/VersionData
Related Topic