24

I am trying to find a way to get the information about the salesforce enterprise user from his auth_token. I want to find the username, email address and role(admin/user) from the auth-token.

Something on the lines of

curl -XGET 'https://na1.salesforce.com/Userinfo' -H "Authorization: Bearter token"

which would give me the required information

I have been looking at the REST API and MetaData API but did not find anything. Preferably I would want this information from a REST API and not some programmatic API. Any help?

1
  • Can anyone shoot me a example of how to build this GET request and pass that Identity Id into it? Thanks!
    – Christian
    Commented Jan 5, 2016 at 19:54

4 Answers 4

29

Assuming you've done OAuth, the OAuth response includes an id field with an Identity Service URL - e.g.:

{
    "id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
    "issued_at":"1296458209517",
    "refresh_token":"5Ae...",
    "instance_url":"https://na1.salesforce.com",
    "signature":"0/1...",
    "access_token":"00D..."
}

GET this URL, passing the access token, and you'll receive the user info. Note the use of -L to follow redirects:

$ curl -L -H 'X-PrettyPrint: 1' -H 'Authorization: Bearer 00D...' https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ
{
    "id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
    "asserted_user":true,
    "user_id":"00550000001fg5OAAQ",
    "organization_id":"00D50000000IZ3ZEAW",
    "username":"[email protected]",
    "nick_name":"user1.2950476911907334E12",
    "display_name":"Sample User",
    "email":"[email protected]",
    "status":{
        "created_date":"2010-11-08T20:55:33.000+0000",
        "body":"Working on OAuth 2.0 article"
    },
    "photos":{
        "picture":"https://c.na1.content.force.com/profilephoto/005/F",
        "thumbnail":"https://c.na1.content.force.com/profilephoto/005/T"
    },
    "urls":{
        "enterprise":"https://na1.salesforce.com/services/Soap/c/{version}/00D50000000IZ3Z",
        "metadata":"https://na1.salesforce.com/services/Soap/m/{version}/00D50000000IZ3Z",
        "partner":"https://na1.salesforce.com/services/Soap/u/{version}/00D50000000IZ3Z",
        "rest":"https://na1.salesforce.com/services/data/v{version}/",
        "sobjects":"https://na1.salesforce.com/services/data/v{version}/sobjects/",
        "search":"https://na1.salesforce.com/services/data/v{version}/search/",
        "query":"https://na1.salesforce.com/services/data/v{version}/query/",
        "recent":"https://na1.salesforce.com/services/data/v{version}/recent/",
        "profile":"https://na1.salesforce.com/00550000001fg5OAAQ"
    },
    "active":true,
    "user_type":"STANDARD",
    "language":"en_US",
    "locale":"en_US",
    "utcOffset":-28800000,
    "last_modified_date":"2011-01-14T23:28:01.000+0000"
}

More info on Identity URLs.

2
  • is there now a way to to fetch this identity information for all the users of the enterprise using the admin's auth token? This is required since I do not know the ids of all users to fetch their information. Is there a way to do it via some call that gives the info of all enterprise users?
    – auny
    Commented May 16, 2013 at 9:38
  • 2
    SELECT Id, Name, Email FROM Users will work, but you'll probably want to filter by profile ID or some other criteria. You can then build the ID URL yourself - it is https://login.salesforce.com/id/[ORG ID]/[USER ID]
    – metadaddy
    Commented May 16, 2013 at 17:10
17

There is an actual endpoint for this now as well: https://login.salesforce.com/services/oauth2/userinfo

See here for the help document

4

For Rest API (Force.com-JavaScript-REST-Toolkit), we have created one more API to get current authenticate user information. You can find more details at link

Please let me know in case of any other information required.

2
  • 1
    The code comment above the userInfo method really helped in understanding what was supposed to be passed as an argument. Thank You. Commented Jul 16, 2014 at 13:09
  • Most welcome contactmatt !!!! Commented Jul 16, 2014 at 14:33
0

If you already have your OAuth token and are familiar with the REST API. The endpoint to hit is:

https://yourinstance./services/data/v46.0/sobjects/User/{ID}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .