Salesforce: Any API for getting user information?

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?

Answer

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":"user@example.com",
    "nick_name":"user1.2950476911907334E12",
    "display_name":"Sample User",
    "email":"user@example.com",
    "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 the Identity Service.

Attribution
Source : Link , Question Author : auny , Answer Author : metadaddy

Leave a Comment