+ Start a Discussion
KJ1122KJ1122 

fetch files through rest API

Hi All,
I am new to Salesforce and looking at the documentation. My basic use case is that i have Salesforce out of the box with no customization. I basically have some files uploaded as attachments and i basicaly want my platform (outside of saleforce) to retreive the files.
Is there an API for the same which we can just implement to fetch the files? (FYI i am using lightning platform)
Best Answer chosen by KJ1122
AnudeepAnudeep (Salesforce Developers) 
You can use the REST API to retrieve the attachments. Use workbench or postman and do a GET to the following URL
https://your_instance/services/data/v43.0/query?q=select id, LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId = '003xxxxxxxxxx'

ContentDocumentId field in ContentDocumentLink stores the file references associated with the parent entity. ContentDocument stores the file relationships & references, while ContentVersion object stores the versions and the file-content references

Anudeep

All Answers

AbhishekAbhishek (Salesforce Developers) 
Hi,

You might find the Working with Salesforce Files

(https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/features_files.htm) documentation is useful to get the REST resource that lists the related files.


A direct SOQL query is also possible against it (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_note.htm)

 and Attachment

(https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm)


For your reference, you can try the suggestion as mentioned below,

https://salesforce.stackexchange.com/questions/72261/how-do-i-fetch-all-the-folders-in-salesforce-using-rest-api

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.


Thanks.

 
AnudeepAnudeep (Salesforce Developers) 
You can use the REST API to retrieve the attachments. Use workbench or postman and do a GET to the following URL
https://your_instance/services/data/v43.0/query?q=select id, LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId = '003xxxxxxxxxx'

ContentDocumentId field in ContentDocumentLink stores the file references associated with the parent entity. ContentDocument stores the file relationships & references, while ContentVersion object stores the versions and the file-content references

Anudeep
This was selected as the best answer
KJ1122KJ1122
Thanks Anudeep. before making the call via postman. Do i need to expose the Apex rest service in Salesforce dev console? Also,how is the authorization handled? Thanks!!
AnudeepAnudeep (Salesforce Developers) 
If you are making the call via postman follow this blog to learn how authorization is taken care of. Thanks
Megan HumbertMegan Humbert
The Proxy Bay maintains a number of places offering links to The Pirate Bay. Such pirate bay proxy servers are hosted in countries where there is no blockade of The Pirate Bay. More information is available on the blocks at Torrentfreak. Pirate Proxy (https://www.techmediabooks.com/pirate-bay-proxy-sites-list-to-unblock-pirate-bay/) sites are simplest ways of bypassing the barrier. For other means of accessing The Pirate Bay, search the Alternative methods.
KJ1122KJ1122
Hi, Is there a way to not use oauth 2.0 and use any other custom mechanism in the connected APP to get the access token?
https://crmcog.com/how-to-call-salesforce-rest-apis/