Newer Version Available
Step Three: Connect to Chatter REST API Using OAuth
Use OAuth to connect to Salesforce and
get an access token. Pass the access token in requests to Chatter 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 organization into these examples:
-
Generate the access token. This cURL command generates an access token:
1curl --form client_id=3MVG9PhR6g6B7ps4xDycwGrI4PvjVZvK9 2 --form client_secret=8870355475032095511 3 --form grant_type=password 4 --form username=admin@seattleapps.com 5 --form password=1Lsfdc! 6 https://login.salesforce.com/services/oauth2/tokenThe response includes the server instance and the access token:1{ 2"id":"https://login.salesforce.com/id/00Di0000000hT9uEAE/005i00000022uIbAAI", 3"issued_at":"1302907727777", 4"instance_url":"https://na1.salesforce.com", 5"signature":"5jcevY5fUai0lWntuSxkwBzWcvRjd01RCOkIBZpyGv0=", 6"access_token":"00DD0000000FJ6T!AQkAQPde_DMF2vGzddfZmBRS95GojDbtA 7 rKkgukAgZP0OVFYY5KkAqhLw9ejeKIlpJ3FgwGAWeRlBiWRt8mfXEuAZGbZNosk" 8} -
To request a Chatter 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://na1.salesforce.com/services/data/v36.0/chatter/users/me 2 -H 'Authorization: Bearer 00DD0000000FJ6T!AQkAQPde_DMF2vGzddfZmBRS95Goj 3 DbtArKkgukAgZP0OVFYY5KkAqhLw9ejeKIlpJ3FgwGAWeRlBiWRt8mfXEuAZGbZNosk'
This example uses these values:
| Property | Value |
|---|---|
| Server instance | na1.salesforce.com |
| client_id | 3MVG9PhR6g6B7ps4xDycwGrI4PvjVZvK9 |
| client_secret | 8870355475032095511 |
| grant_type | password The value of grant_type depends on the OAuth authentication flow you are using. |
| username | admin@seattleapps.com |
| password | 1Lsfdc! |