3

I'm using the rest api to query the data from an account: Account/001234abcde and images attached to the account are stored like this:

https://c.na20.content.force.com/servlet/servlet.FileDownload?file=00THEFILEID

I can see the image no problem from the browser if I'm currently authenticated in saleforce but the link does not work if I'm not authenticated and redirects me to the login page.

Is it possible to get the proper image data with the rest api without going through the above link? If not, how should images be uploaded to an account so that they can be retrieved easily using rest api?

Solution

Thanks to guy for the answer. Blob Retrieve is useful in this case. Here's the solution that I am using:

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Attachment/00THEFILEID/body -H "Authorization: Bearer token"
1
  • Force.com Sites can be used to make data accessible without authentication including through custom REST APIs. Perhaps you can add more detail to your question about what the client for the data is so that you get more clear-cut answers.
    – Keith C
    Sep 30, 2014 at 19:20

1 Answer 1

2

Assuming that you are referring to Account record attachments..

First step will be to get the proper attachment id's. You can do that by querying the Account or the Attachment table, as described here https://stackoverflow.com/questions/13870089/how-to-display-salesforce-attachments-in-asp-net-website-to-download

Second step will be downloading the actual binary attachments. This can be done with the rest api's 'retrieve' command: http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#CSHID=dome_sobject_blob_retrieve.htm|StartTopic=Content%2Fdome_sobject_blob_retrieve.htm|SkinName=webhelp

Or by decoding the 'body' field as also described in Eyescream's post (the first link)

4
  • Do these links address the question of unauthenticated access?
    – Keith C
    Sep 30, 2014 at 19:32
  • I didn't see any question on unauthenticated access, though there is a side comment on that. In my view the question is on getting image date with the rest api without going through the link. I agree with your comment above that the question could be improved. Sep 30, 2014 at 19:37
  • Looks like you are right!
    – Keith C
    Sep 30, 2014 at 20:04
  • Yes, too bad, it would have been interesting to learn more about using Rest API to fetch attachments without authentication :-) Sep 30, 2014 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.