You need to sign in to do that
Don't have an account?
Ricky Fair
Using the REST API to Download documents/Attachments
SalesForce Devs,
I am simply trying to invocate a GET request call to download a file/document, previously uploaded to Salesforce, from Salesforce. I am able to successfully authenticate, and perform other calls. It appears that the only way to download the file according to the SFDC documentation, listed in link below, is by providing a document/attachment ID. Which, I've tried determine and find without success, and I have searched throughout the system very thoroughly and have not been able to determine what the document/attachment IDs are for the files that I am attemptign to test download with.
Also, what are the differences between documents and attachements? Should I be using the Files API instead?
https://developer.salesforce.com/docs/api-explorer/sobject/Attachment
https://developer.salesforce.com/docs/api-explorer/sobject/Document
Thank you for any help insight you are able to provide! There's no way I am the first person to attempt this!
RF
I am simply trying to invocate a GET request call to download a file/document, previously uploaded to Salesforce, from Salesforce. I am able to successfully authenticate, and perform other calls. It appears that the only way to download the file according to the SFDC documentation, listed in link below, is by providing a document/attachment ID. Which, I've tried determine and find without success, and I have searched throughout the system very thoroughly and have not been able to determine what the document/attachment IDs are for the files that I am attemptign to test download with.
Also, what are the differences between documents and attachements? Should I be using the Files API instead?
https://developer.salesforce.com/docs/api-explorer/sobject/Attachment
https://developer.salesforce.com/docs/api-explorer/sobject/Document
Thank you for any help insight you are able to provide! There's no way I am the first person to attempt this!
RF
Thank you for posting this question.
As per my knowledge if you give any request the response will give you in string format.So based on ur response you need to do some logic.
In the same SF URLs wt u gave for calling Attachment to just getting id and Success response here YOU won't expect attachment body.and also you hitting standard salesforce Endpoint URL.So it's returning another URL for body.
So my suggestion is create your own apex class having strong endpoint URL with HTTPGET method for returning direct body instead of another URL(as showning in standard response) and this response also will give you in string format only.
if you want to download attachments u can redirect u r url with passing id of record. The download URL is:
https://(DOMAINNAME)--c.ap4.content.force.com/servlet/servlet.FileDownload?file=00P6F00002r55f5(Record ID).
You can set this link as a redirect page at you created custom URL apex class only (IF you want any help on this ask me I'll send you draft code).So if the apex class is calling the above link the particular file automatically gets downloaded. If it's a success no need to look into response body.
The only difference in attachment and documents is attachments have parentId, so file can be visible at record related list level.
Better check with public links for downloading attachments using public URL no need to login salesforce if clink links the respective file automatically downloads. For generating public URL of attachments is gone through https://help.salesforce.com/articleView?id=collab_files_sharing_via_link.htm&type=5 (https://help.salesforce.com/articleView?id=collab_files_sharing_via_link.htm&type=5)
I hope this is helpfull to you.
That is very helpful, but I dont think it fully addresses my issue. I will add clarification.
End goal: To be able to download all files from SFDC for a specific user, opportunity, lead, etc. by calling an SFDC API, and providing the Object type (user, opportunity, lead, etc.) and the ID associated with that user, opportunity, lead, etc.
Also, I have not been able to obtain/identfiy the attachment ID nor Document ID. I tried to determin what the document ID is, to attempt to download it from the Attachment/document APIs. I searched the UI, and associated objects that may provide the document/attachment ID.
From your post, it sounds like the document/attachment ID will work with an APEX class that redirect me to a seperate URL for download. How do I first get the attachment/document ID?
After uploading 3 files to a lead I created in the SFDC UI, I am able to make the files public, and download them. I performed an inspection on the networking traffic they produce when downloading, I found certain ID numbers etc. but am unable to confirm they are the ID numbers that I need. Please note the End goal I listed above, is there no simple way to tap into SFDC APIs after authenticating to download releavant attachments to an object?
Thanks again for your help!
Ricky
I do agree with you using SFDC API we can't download attachments. That is the reason I gave you go through custom code.
ok fine, can you please describe your business scenario so that anybody can help you including me also on time with a point to point explanation.
Regards
Vijay
Thank you again for your response.
Here is what would be ideal for my organization, so that we can better integrate with SalesForce. I believe this would also be very beneficial for the broader SalesForce userbase/audience:
Thank you,
Ricky
If the requestor should give any attribute value you want to find attachment details that are related to attributes?
For example: If you gave CaseId while calling you expecting all the attachments under that caseid?
If yes you must go with custom API it's not possible using SF standard API.
If you fine with custom API all requests are possible which mentioned above.
For Reference:
Example 1: Using ParentId
@RestResource (urlMapping='/GetAttachment*')
global with sharing class GetAttachmentRestAPI {
@HttpGet
global static Account getattachment() {
RestRequest req = RestContext.request;
String parentId = req.params.get('parentid');
Attachment att = [SELECT Id, Name,body FROM Attachment WHERE ParentId =: parenntid];
return att;
}
}
Endpoit URL:htttp://<Domain+salesforce.com>/services/apexrest/GetAttachment?parentid='001324345654532';