Connect to REST-based APIs

Use these steps to connect your applications directly to the REST-based APIs, including REST API, Bulk API 2.0, and Connect API.

If you want to test API operations, we recommend that you use the Salesforce collection for Postman. The Postman collection includes a function that automatically obtains an authorization token and applies it to your subsequent API requests. For more information, see Quick Start: Connect Postman to Salesforce on Trailhead.

Before you complete these steps, create a Connected App. For more information, see Create a Connected App.

Also, activate OAuth2 settings in the Connected App. For more information, see Enable OAuth Settings for API Integration.

After you activate the OAuth2 settings for the Connected App, copy the Consumer Key and Consumer Secret values for the app. You use these values to obtain an authentication token.

Issue a POST request to the /services/oauth2/token endpoint. The body of the request must contain the consumer ID and secret for your Connected App. It must also contain the username and password of your API user.

If your request is accepted, the API returns a 200 response that contains information about the token.

When you make subsequent calls to REST API or Bulk API 2.0, provide this token as a header using the Bearer token syntax.

An easy way to test your authentication token is to issue a GET call to the /services/data/API_VERSION/limits endpoint.

If your request is successful, the response includes information about the API usage limits that apply to your account.

Authentication tokens expire based on the session policy for your org. When your token expires, issue another POST request to the authentication endpoint to obtain a new token.