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 to create an external client app and configure an OAuth flow before starting this task.
To make a request to Salesforce, substitute values from your org and external client app into these examples.
-
Generate the access token.
This cURL command generates an access token.
The value of
grant_typedepends on the OAuth authentication flow that you’re using. This example uses the OAuth 2.0 Client Credentials Flow for Server-to-Server Integration, so the grant type isclient_credentials. The response includes the server instance and the access token. -
To request a Connect REST API resource, use the returned
instance_urlas the server instance. Pass the returnedaccess_tokenas aBearertoken in theAuthorizationrequest header.
If you get an unsupported_grant_type error, check the syntax of your cURL command. If you’re using Windows Command Prompt, replace single quotes (’) in the examples with double quotes (”). For additional information about OAuth errors, see OAuth 2.0 Authorization Errors.