function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ahmad KharbatAhmad Kharbat 

How to download Chatter Files from API?

Hi there.. I'm trying to download Files through the API

When I fetch the File info... the value of the [downloadUrl] is:
/services/data/v29.0/connect/files/069410000002wABAAY/content?versionNumber=1

Calling this endpoint in the API returns null or empty result.

Any idea what should be done here?
 
Best Answer chosen by Ahmad Kharbat
Ahmad KharbatAhmad Kharbat
Hi Malathan, Yes I figured it out and I wonder why is this not documented well yet, I kinda scanned the whole documentation with no clear answer. Anyway, luckily I got it figured.

1. Make an API call to   "connect/files/File-Id" 

2. In order to download the file you need to grab its binary content first, and then handle the download yourself.  In order to grab the binary content, you need to make an oauth-token-authenticated HTTP request to the downloadUrl provided in the object. For instance You can do this using cURL.

3. Once you grab the content, you can then print it using your programming language, after setting the header to the proper MIME type.

 

All Answers

karthikeyan perumalkarthikeyan perumal
Hello, 

Yes. Based on the Chatter Collaboration datamodel (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm) or the Chatter Cheat sheet (http://media.developerforce.com/cheatsheets/SF_chatter_4Pg_HR.pdf) you can find out that it's the ContentDocument table you're looking for if you want to find chatter files. You can query this through SOQL like this:
 
SELECT Id,Title,createddate FROM ContentDocument

Using the REST API you can either use the query call
/services/data/v29.0/query?q=SELECT+Id,Title,createddate+FROM+ContentDocument

or use the ContentDocument endpoint for describe, recent items or record details
/services/data/v29.0/sobjects/ContentDocument   

/services/data/v29.0/sobjects/ContentDocument/record_ID


Hope this will help you, 

Mark Best ANSWER if its works for you. 

Thanks
karthik
 
Ahmad KharbatAhmad Kharbat
Great. I could pull the File information as indicated below. However I still don't see how can I download it?

It is there a way to stream its content, or generate a download link through the API ?
Array
(
    [attributes] => Array
        (
            [type] => ContentDocument
            [url] => /services/data/v38.0/sobjects/ContentDocument/069410000002wIkAAI
        )

    [Id] => 069410000002wIkAAI
    [CreatedById] => 00541000001R2iWAAS
    [CreatedDate] => 2016-11-14T22:40:51.000+0000
    [LastModifiedById] => 00541000001R2iWAAS
    [LastModifiedDate] => 2016-11-14T22:47:08.000+0000
    [IsArchived] => 
    [ArchivedById] => 
    [ArchivedDate] => 
    [IsDeleted] => 
    [OwnerId] => 00541000001R2iWAAS
    [SystemModstamp] => 2016-11-15T18:12:46.000+0000
    [Title] => ACME3
    [PublishStatus] => P
    [LatestPublishedVersionId] => 068410000002qOeAAI
    [ParentId] => 
    [LastViewedDate] => 2016-11-15T18:12:04.000+0000
    [LastReferencedDate] => 2016-11-15T18:12:04.000+0000
    [Description] => 
    [ContentSize] => 11
    [FileType] => TEXT
    [FileExtension] => txt
    [SharingOption] => A
    [ContentModifiedDate] => 2016-11-14T22:40:51.000+0000
    [ContentAssetId] => 
)

 
Ahmad KharbatAhmad Kharbat
Note: Users who will download the File are Anonymous or Non Salesforce authenticated.
Malathan2Malathan2
Did you ever figure this out?  I am working on same issue.
Ahmad KharbatAhmad Kharbat
Hi Malathan, Yes I figured it out and I wonder why is this not documented well yet, I kinda scanned the whole documentation with no clear answer. Anyway, luckily I got it figured.

1. Make an API call to   "connect/files/File-Id" 

2. In order to download the file you need to grab its binary content first, and then handle the download yourself.  In order to grab the binary content, you need to make an oauth-token-authenticated HTTP request to the downloadUrl provided in the object. For instance You can do this using cURL.

3. Once you grab the content, you can then print it using your programming language, after setting the header to the proper MIME type.

 
This was selected as the best answer