Newer Version Available
Step Three: Connect to Connect REST API Using OAuth
Use OAuth to connect to Salesforce and get an access token. Pass the access token in
requests to Connect REST API.
Complete Step Two: Set Up Authorization and create a connected app before starting this task.
This table maps the terms used in the connected app you created to the OAuth properties used in the examples. The OAuth 2.0 specification uses the word “client” instead of “consumer.”
| Connected App Application Label | Value in Example |
|---|---|
| Consumer Key | client_id |
| Consumer Secret | client_secret |
To make a request to Salesforce, substitute values from your org into these examples.
-
Generate the access token.
This cURL command generates an access token.
1curl -X POST 'https://instance_name.my.salesforce.com/services/oauth2/token' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'grant_type=client_credentials' \--data-urlencode 'client_id=3MVG9VwZxxW3bBQjhE6m21CG2nSS4WC.GNbZCtKeQxFH7218ns6xOLCNnJVKnZFTZWKzt2qwSFqt2taMt5mcr' \--data-urlencode 'client_secret=8A4BE698BCA216718ECB0B1DCA294C69732EAD9472A1790F8FED38DD2E02B5FA'The response includes the server instance and the access token.1{ 2"access_token": "00DS7000000oxzo!AR8AQPXAhJNveaXDdPzbrtXqPykdVxBxtbLycpiyPmKyJm0Ku8gKKztulObJ1dhJU8Jt9W8k7FySsPAkvCnsadT_AbJTSW5T", 3"signature": "nUFHwtfIGLKDTHcLWmDBG8frv0t+HQGl/iCZFIQUarE=", 4"token_format": "opaque", 5"instance_url": "https://instance_name.my.salesforce.com" 6"id": "https://login.salesforce.com/id/00Dd000000XXXXXXX/005d000000XXXXX", 7"token_type": "Bearer", 8"issued_at": "1678833535086" 9} -
To request a Connect REST API resource, use the returned instance_url as the server instance. Pass
the returned access_token as a Bearer token in the Authorization request header.
1curl -X GET https://instance_name.my.salesforce.com/services/data/v59.0/chatter/users/me 2 -H 'Authorization: Bearer 00DS7000000oxzo!AR8AQPXAhJNveaXDdPzbrtXqPykdVxBxtbLycpiyPmKyJm0Ku8gKKztulObJ1dhJU8Jt9W8k7FySsPAkvCnsadT_AbJTSW5T'
This example uses these values.
| Property | Value |
|---|---|
| client_id | 3MVG9VwZxxW3bBQjhE6m21CG2nSS4WC.GNbZCtKeQxFH7218ns6xOLCNnJVKnZFTZWKzt2qwSFqt2taMt5mcr |
| client_secret | 8A4BE698BCA216718ECB0B1DCA294C69732EAD9472A1790F8FED38DD2E02B5FA |
| grant_type | The value of grant_type depends on the OAuth authentication flow you’re using. |