Get Started
Configure your Org
Which API Should I Use?
Connect to REST-based APIs
Connect to SOAP API
Connect to Direct Email Send API
Security
To connect to any REST-based API, such as REST API, Bulk API 2.0, or Connect API, follow these steps. For testing, use the Salesforce collection for Postman, which handles authorization for you.
Before you complete these steps, create an external client app.
After you create the external client app, activate OAuth2 settings.
Finally, after you activate the OAuth2 settings, copy the Consumer Key and Consumer Secret. The Consumer Key maps to the client_id value that you use to obtain the authentication token, and the Consumer Secret maps to the client_secret.
Issue a POST request to the /services/oauth2/token endpoint. The body of the request must contain the consumer ID and secret for your external client app. It must also contain the username and password of your API user.
1POST /services/oauth2/token HTTP/1.1
2Host: MY_DOMAIN_LOGIN_URL
3Content-Type: application/json
4
5{
6 "grant_type": "password",
7 "client_id" : CONSUMER_KEY,
8 "client_secret": CONSUMER_SECRET,
9 "username": USERNAME,
10 "password": PASSWORD
11}If the API accepts your request, it returns a 200 response with information about the token.
1{
2 "access_token": "YOUR_ACCESS_TOKEN",
3 "instance_url": "https://MY_DOMAIN_LOGIN_URL",
4 "id": "https://login.salesforce.com/id/wRYO4cyiogGJuSu/HQ7tfVfduzymohBchM",
5 "token_type": "Bearer",
6 "issued_at": "1722887135000",
7 "signature": "RESPONSE_SIGNATURE"
8}Copy the value of the access_token property.
When you make subsequent calls to REST API or Bulk API 2.0, provide your bearer token as an Authorization header.
1Authorization: Bearer YOUR_AUTH_TOKENAn easy way to test your authentication token is to issue a GET call to the /services/data/API_VERSION/limits endpoint.
1GET /services/data/API_VERSION/limits HTTP/1.1
2Host: generativecampaign248.test1.lightning.pc-rnd.force.com
3Authorization: Bearer YOUR_ACCESS_TOKENIf your request is successful, the response includes information about the API usage limits that apply to your account.
1{
2 "ActiveScratchOrgs": {
3 "Max": 3,
4 "Remaining": 3
5 },
6 "AnalyticsExternalDataSizeMB": {
7 "Max": 40960,
8 "Remaining": 40960
9 },
10 "ConcurrentAsyncGetReportInstances": {
11 "Max": 200,
12 "Remaining": 200
13 },
14 ...
15}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.