Newer Version Available

This content describes an older version of this product. View Latest

Step One: Set Up Authorization

Using REST API requires an access token to successfully send requests. You can get an access token using the username-password authorization flow.

Usually, we recommend that you obtain an access token using an OAuth authorization flow that doesn’t require you to include credentials in the request. However, the only authorization flow that you can use with cURL is the username-password authorization flow. For the purposes of this quick start, use this method to obtain an access token.

Use the username-password authorization flow only if you’re handling your own credentials. Review the recommendations and restrictions for this authorization flow in OAuth 2.0 Username-Password Flow for Special Scenarios in Salesforce Help.

Important

Before you obtain an access token, make sure that you’ve completed all the prerequisites listed in this quick start.

Send a request to the Salesforce OAuth endpoint using this cURL template:

1curl https://MyDomainName.my.salesforce.com/services/oauth2/token -d 'grant_type=password' -d 'client_id=consumer-key' -d 'client_secret=consumer-secret' -d 'username=my-login@domain.com' -d 'password=my-password'

Replace MyDomainName with the domain for your Salesforce org. Replace consumer-key and consumer-secret with the consumer key and consumer secret of your connected app, which you obtained in the prerequisite steps. Replace my-login@domain.com and my-password with your login credentials for your Salesforce org.

If the request was unsuccessful and you’re unable to log in, see Troubleshoot Login Issues in Salesforce Help.

If the request was successful, the response contains an access token that you can use in other requests to access your data in Salesforce. For example:

1{"access_token":"00D5e000001N20Q!ASAAQEDBeG8bOwPu8NWGsvFwWNfqHOp5ZcjMpFsU6yEMxTKdBuRXNzSZ8xGVyAiY8xoy1KYkaadzRlA2F5Zd3JXqLVitOdNS",
2 "instance_url":"https://MyDomainName.my.salesforce.com",
3 "id":"https://login.salesforce.com/id/00D5e000001N20QEAS/0055e000003E8ooAAC",
4 "token_type":"Bearer",
5 "issued_at":"1627237872637",
6 "signature":"jmaZOgQyqUxFKAesVPsqVfAWxI62O+aH/mJhDrc8KvQ="}