Send REST Requests with cURL

The examples in this guide use the cURL tool to send HTTP requests that access, create, and manipulate resources in Salesforce. If you use a different tool to send requests, you can use the same elements from the cURL examples to send requests.

cURL is pre-installed on many Linux and macOS systems. Windows users can download a version at curl.haxx.se/. When using HTTPS on Windows, ensure that your system meets the cURL requirements for SSL.

cURL is an open-source tool and isn’t supported by Salesforce.

Note

Attaching Request Bodies

Many examples include request bodies—JSON or XML files that contain data for the request. When using cURL, save these files to your local system and attach them to the request using the —data-binary or -d option.

This example attaches the new-account.json file.

curl https://MyDomainName.my.salesforce.com/services/data/v64.0/sobjects/Account/ -H "Authorization: Bearer access-token" -H “Content-Type: application/json” —data-binary @new-account.json -X POST

Handling Exclamation Marks in Access Tokens

When you run cURL examples, you can get an error on macOS and Linux systems due to the presence of the exclamation mark (!) special character in OAuth access tokens. To avoid getting this error, either escape the exclamation mark or use single quotes.

To escape the exclamation mark in the access token, insert a backslash before it (\!) when the access token is enclosed within double quotes. For example, the access token string in this cURL command has the exclamation mark (!) escaped.

curl https://MyDomainName.my.salesforce.com/services/data/v64.0/ -H "Authorization: Bearer 00D50000000IehZ\!AQcAQH0dMHZfz972Szmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1E6LYUfiDUkWe6H34r1AAwOR8B8fLEz6n04NPGRrq0FM"

Or, you can enclose the access token within single quotes.

curl https://MyDomainName.my.salesforce.com/services/data/v64.0/ -H 'Authorization: Bearer 00D50000000IehZ!AQcAQH0dMHZfz972Szmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1E6LYUfiDUkWe6H34r1AAwOR8B8fLEz6n04NPGRrq0FM'