My goal is to download all attachments of a given Case. I was managed to perform the needed queries to and I have a pointer to the ContentVersion object I need.

They problem is that I don't know how to download the attachment. I believe I need the VersionData field, which holds the file in binary format.

Another limitation that I have is that I'm using a Linux environment by means of its CLI prompt. I already made an authentication to SF by using SFDX API provided by SalesForce, but I cannot find a way to combine SFDX API with REST API's GET command to fetch the needed file so it will be downloaded to my Linux machine.

Please advise.



1 Answer 1


Why don't you try curl to retrieve attachments.

As you already have the ContentVersion Id you can fetch VersionData and FileExtension by an SOQL and then can simply run a curl command

curl <your_instance_url>/ContentVersionData -H "Authorization : Bearer {access_token}" -o nameOfFile
  • instead of getting the needed file, I'm getting a small text file with the following data in it Aug 18, 2020 at 8:58
  • var url = window.location.pathname + window.location.hash; if(window.location.search && window.location.search.length > 1){ url += window.location.search; // #189617 } var loc = 'https://*********.salesforce.com?ec=302&startURL='+encodeURIComponent(url); window.location = loc; </script> Aug 18, 2020 at 9:00
  • when I put manually the URL in my web browser, the needed file being successfully downloaded. Aug 18, 2020 at 9:04
  • Not sure where this get wrong but I was able to download file successfully. Might be an issue with filename. it should be name.fileExtension
    – Pmanglani
    Aug 18, 2020 at 9:47
  • I'm trying to download a.tar file, and I'm naming it myfile.tar. Aug 18, 2020 at 9:49

Not the answer you're looking for? Browse other questions tagged .