How do I generate an SHA for uploading a file to the Vercel API?

When using the Vercel API to create a deployment, you first need to upload your files associated with this deployment. An SHA is required to upload each file. In this article, we describe how to generate the SHA for each file from the command line and then use it to upload the file to the Vercel API.

On UNIX operating systems, the easiest way to do this is to use the built-in command shasum. For example, for a file named vercel.json, run the following command:

echo -n vercel.json | shasum
Using the built-in command shasum to generate an SHA for vercel.json.

The SHA will be outputted in the command line. Copy it to a safe location.

Next, you will use the SHA as the header x-vercel-digest for the POST request with the Vercel API. In the case of the vercel.json above, you can use the following CURL command:

curl --location --request POST 'https://api.vercel.com/v2/now/files' \
--header 'x-vercel-digest: `SHA`' \
--header 'Authorization: Bearer `mytoken`' \
--header 'Content-Type: text/plain' \
--data-raw '`content of the vercel.json file`'
Uploading the contents of the vercel.json file using your SHA and token mytoken.

The contents of the vercel.json in the command above is the exact copy and paste of the contents of the vercel.json file. The response will be 200 with an empty object.

You are now ready to create a deployment with the Vercel API.

curl --location --request POST 'https://api.vercel.com/v12/now/deployments' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer `mytoken` \
--data-raw '{
"name": "my-instant-deployment",
"files": [
{
"file": "vercel.json",
"sha": "`SHA`",
"size": `filesizeinbytes`
}
],
"projectSettings": {
"framework": null
}
}'
Creating a new deployment using the uploaded file vercel.json with size filesizeinbytes, the SHA and the token mytoken.

If you uploaded multiple files, each with a different SHA, append the files array in the above POST request with an object for each file.

In most cases, your project will contain many files and folders. You can write a script using the language of your choice (such as bash or node) and the pattern described above to upload your project files, obtain the SHA values, and then deploy your project using the SHA, file size, and filename values for each file.

Couldn't find the guide you need?