As a Salesforce administrator or developer, you may need to download a ContentVersion file through the Salesforce REST API using Curl. In this post, we’ll show you how to download the file with Curl in a few simple steps.
First, you’ll need to execute a query and extract the Content Version File ID. To do this, you can use Workbench or the REST explorer and issue a query like this:
SELECT Id, VersionData
FROM ContentVersion
WHERE Title = 'titleOfFile'
Or
SELECT Title, VersionData
FROM ContentVersion
WHERE Id = '0684V00000Qhf3mABB'
To download a ContentVersion
file in Salesforce through the REST API, you’ll need to make a GET
request to this endpoint:
/services/data/vXX.0/sobjects/ContentVersion/{recordId}/VersionData
Where <strong>XX</strong>
is the Salesforce API version you’re using (e.g. 56 for API version 56), and recordId
is the unique identifier of the ContentVersion
record you want to retrieve.
Here’s a sample request in cURL:
curl -H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/octet-stream" \
-X GET https://<instance>.salesforce.com/services/data/vXX.0/sobjects/ContentVersion/{recordId}/VersionData
Note that you’ll need to replace the following placeholder values:
<ACCESS_TOKEN>
: with a valid Salesforce access token.<instance>
: with your Salesforce instance name (e.g.na1
,eu0
, etc.).XX
: with the Salesforce API version you’re using.{recordId}
: with the unique identifier of theContentVersion
record you want to retrieve.
Also, note that you’ll need to set the Content-Type
header to application/octet-stream
to indicate that you’re downloading a binary file.
In the response, the binary data of the ContentVersion
file will be included in the body. You can write this data to a file on your local machine to save it.