Query for User Information
A connected app can query the UserInfo endpoint for information about the user associated with the connected app’s access token. Salesforce returns basic personal information about the user and important endpoints that the connected app can talk to, such as photos and accessible API endpoints. This UserInfo endpoint provides access to information only for the current user. It doesn’t give access to other users in the org.
Required Editions
| Available in: both Salesforce Classic and Lightning Experience |
| Available in: All Editions |
The UserInfo endpoint is a RESTful API defined by OpenID Connect. The format of the endpoint’s URL is: https://login.salesforce.com/services/oauth2/userinfo.
Here’s the flow for querying the UserInfo Endpoint.
- The connected app sends a query to the Salesforce UserInfo endpoint. The query must contain the connected app’s access token.
- Salesforce responds with the user’s information.
Query the UserInfo Endpoint
Use these parameters to query the UserInfo endpoint. You can use the
access token in an authorization request header or in a request with the oauth_token parameter.
Salesforce UserInfo Endpoint Responds
After making a valid request, Salesforce returns the information in JSON format by default, or the format specified in the format parameter.
The response includes values listed in the OpenID Connect Basic Client Profile, Salesforce user ID, org ID, feed, and profile URLs.
In the response, the email_verified attribute reflects whether users
verify their email after this scenario occurs: For example, a Salesforce admin creates the user
Roberta Smith. Roberta receives a “Welcome to Salesforce” email message with a link to verify
her account. After she clicks the link, the email_verified value is set to
true.
- They change their email address
- They change their password, or a Salesforce admin resets their password
- They verify their identity when logging in from a new device or browser
- A Salesforce admin creates them as a new user
The following is a response in JSON format.
{"sub":"https://login.salesforce.com/id/00Dx000.../005x000...",
"user_id":"005x000...",
"organization_id":"00Dx000...",
"name":"yourInstance LastName",
"email":"user1@1135222488950007.com",
"email_verified":true,"given_name":"yourInstance","family_name":"LastName",
"zoneinfo":"America/Los_Angeles",
"photos":{"picture":"https://yourInstance.salesforce.com/profilephoto/005/F","thumbnail":"https://yourInstance.salesforce.com/profilephoto/005/T"},
"profile":"https://yourInstance.salesforce.com/005x000...",
"picture":"https://yourInstance.salesforce.com/profilephoto/005/F",
"address":{"country":"us"},
"urls":{"enterprise":"https://yourInstance.salesforce.com/services/Soap/c/{version}/00Dx00...",
"partner":"https://yourInstance.salesforce.com/services/Soap/u/{version}/00Dx00...",
"rest":"https://yourInstance.salesforce.com/services/data/v{version}/",
"sobjects":"https://yourInstance.salesforce.com/services/data/v{version}/sobjects/",
"search":"https://yourInstance.salesforce.com/services/data/v{version}/search/",
"query":"https://yourInstance.salesforce.com/services/data/v{version}/query/",
"recent":"https://yourInstance.salesforce.com/services/data/v{version}/recent/",
"profile":"https://yourInstance.salesforce.com/005x000...",
"feeds":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/feeds",
"groups":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/groups",
"users":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/users",
"feed_items":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/feed-items"},
"active":true,"user_type":"STANDARD","language":"en_US","locale":"en_US",
"utcOffset":-28800000,"updated_at":"2013-12-02T18:46:42Z"}The following is a response in XML format.
<?xml version="1.0" encoding="UTF-8"?>
<user>
<sub>https://login.salesforce.com/id/00Dx000.../005x000...</sub>
<user_id>005x000...</user_id>
<organization_id>00Dx000...</organization_id>
<preferred_username>user1@1135222488950007.com</preferred_username>
<nickname>user1.3860098879512678E12</nickname>
<name>user1 LastName</name>
<email>user1@1135222488950007.com</email>
<email_verified>true</email_verified>
<given_name>user1</given_name>
<family_name>LastName</family_name>
<zoneinfo>America/Los_Angeles</zoneinfo>
<photos>
<picture>https://yourInstance.salesforce.com/profilephoto/005/F</picture>
<thumbnail>https://yourInstance.salesforce.com/profilephoto/005/T</thumbnail></photos>
<profile>https://yourInstance.salesforce.com/005x000...</profile>
<picture>https://yourInstance.salesforce.com/profilephoto/005/F</picture>
<address>
<country>us</country>
</address>
<urls>
<enterprise>https://yourInstance.salesforce.com/services/Soap/c/{version}/00Dx0000002rIh1</enterprise>
<metadata>https://yourInstance.salesforce.com/services/Soap/m/{version}/00Dx0000002rIh1</metadata>
<partner>https://yourInstance.salesforce.com/services/Soap/u/{version}/00Dx0000002rIh1</partner>
<rest>https://yourInstance.salesforce.com/services/data/v{version}/</rest>
<sobjects>https://yourInstance.salesforce.com/services/data/v{version}/sobjects/</sobjects>
<search>https://yourInstance.salesforce.com/services/data/v{version}/search/</search>
<query>https://yourInstance.salesforce.com/services/data/v{version}/query/</query>
<recent>https://yourInstance.salesforce.com/services/data/v{version}/recent/</recent>
<profile>https://yourInstance.salesforce.com/005x000...</profile>
<feeds>https://yourInstance.salesforce.com/services/data/v{version}/chatter/feeds</feeds>
<groups>https://yourInstance.salesforce.com/services/data/v{version}/chatter/groups</groups>
<users>https://yourInstance.salesforce.com/services/data/v{version}/chatter/users</users>
<feed_items>https://yourInstance.salesforce.com/services/data/v{version}/chatter/feed-items</feed_items>
</urls>
<active>true</active>
<user_type>STANDARD</user_type>
<language>en_US</language>
<locale>en_US</locale>
<utcOffset>-28800000</utcOffset>
<updated_at>2013-12-02T18:46:42.000Z</updated_at>
</user>Here are descriptions for the returned parameters.
The following are possible responses from Salesforce to an invalid request.
| Error Code | Request Problem |
|---|---|
| 403 (forbidden) — HTTPS_Required | HTTP |
| 403 (forbidden) — Missing_OAuth_Token | Missing access token |
| 403 (forbidden) — Bad_OAuth_Token | Invalid access token |
| 403 (forbidden) — Wrong_Org | Users in a different org |
| 404 (not found) — Bad_Id | Invalid or bad user or org ID |
| 404 (not found) — Inactive | Deactivated user or inactive org |
| 404 (not found) — No_Access | User lacks proper access to org or information |
| 404 (not found) — No_Site_Endpoint | Request to an invalid endpoint of a site |
| 404 (not found) — Internal Error | No response from server |
| 406 (not acceptable) — Invalid_Version | Invalid version |
| 406 (not acceptable) — Invalid_Callback | Invalid callback |

