Chilkat Online Tools

SQL Server / Salesforce Platform APIs / User Info

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://login.salesforce.com{{site}}/services/oauth2/userinfo', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "sub": "https://login.salesforce.com/id/00D.../005...",
    --   "user_id": "005...",
    --   "organization_id": "00D...",
    --   "preferred_username": "<username>",
    --   "nickname": "<nickname>",
    --   "name": "<name>",
    --   "email": "<email>",
    --   "email_verified": true,
    --   "given_name": "<name>",
    --   "family_name": "<name>",
    --   "zoneinfo": "Europe/Paris",
    --   "photos": {
    --     "picture": "https://<file_domain>/profilephoto/005/F",
    --     "thumbnail": "https://<file_domain>/profilephoto/005/T"
    --   },
    --   "profile": "https://<my_domain>/005",
    --   "picture": "https://<file_domain>/profilephoto/005/F",
    --   "address": {
    --     "country": "FR"
    --   },
    --   "is_salesforce_integration_user": false,
    --   "urls": {
    --     "enterprise": "https://<my_domain>/services/Soap/c/{version}/00D...",
    --     "metadata": "https://<my_domain>/services/Soap/m/{version}/00D...",
    --     "partner": "https://<my_domain>/services/Soap/u/{version}/00D...",
    --     "rest": "https://<my_domain>/services/data/v{version}/",
    --     "sobjects": "https://<my_domain>/services/data/v{version}/sobjects/",
    --     "search": "https://<my_domain>/services/data/v{version}/search/",
    --     "query": "https://<my_domain>/services/data/v{version}/query/",
    --     "recent": "https://<my_domain>/services/data/v{version}/recent/",
    --     "tooling_soap": "https://<my_domain>/services/Soap/T/{version}/00D...",
    --     "tooling_rest": "https://<my_domain>/services/data/v{version}/tooling/",
    --     "profile": "https://<my_domain>/0052o00000DOJ1PAAX",
    --     "feeds": "https://<my_domain>/services/data/v{version}/chatter/feeds",
    --     "groups": "https://<my_domain>/services/data/v{version}/chatter/groups",
    --     "users": "https://<my_domain>/services/data/v{version}/chatter/users",
    --     "feed_items": "https://<my_domain>/services/data/v{version}/chatter/feed-items",
    --     "feed_elements": "https://<my_domain>/services/data/v{version}/chatter/feed-elements",
    --     "custom_domain": "https://<my_domain>"
    --   },
    --   "active": true,
    --   "user_type": "STANDARD",
    --   "language": "en_US",
    --   "locale": "fr_FR_EURO",
    --   "utcOffset": 3600000,
    --   "updated_at": "<datetime>",
    --   "is_app_installed": true
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @v_sub nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_sub OUT, 'sub'
    DECLARE @user_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @user_id OUT, 'user_id'
    DECLARE @organization_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @organization_id OUT, 'organization_id'
    DECLARE @preferred_username nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @preferred_username OUT, 'preferred_username'
    DECLARE @nickname nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @nickname OUT, 'nickname'
    DECLARE @name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'name'
    DECLARE @email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'email'
    DECLARE @email_verified int
    EXEC sp_OAMethod @jResp, 'BoolOf', @email_verified OUT, 'email_verified'
    DECLARE @given_name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @given_name OUT, 'given_name'
    DECLARE @family_name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @family_name OUT, 'family_name'
    DECLARE @zoneinfo nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @zoneinfo OUT, 'zoneinfo'
    DECLARE @Picture nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Picture OUT, 'photos.picture'
    DECLARE @Thumbnail nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Thumbnail OUT, 'photos.thumbnail'
    DECLARE @profile nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @profile OUT, 'profile'
    DECLARE @picture nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @picture OUT, 'picture'
    DECLARE @Country nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Country OUT, 'address.country'
    DECLARE @is_salesforce_integration_user int
    EXEC sp_OAMethod @jResp, 'BoolOf', @is_salesforce_integration_user OUT, 'is_salesforce_integration_user'
    DECLARE @Enterprise nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Enterprise OUT, 'urls.enterprise'
    DECLARE @Metadata nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Metadata OUT, 'urls.metadata'
    DECLARE @Partner nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Partner OUT, 'urls.partner'
    DECLARE @v_Rest nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Rest OUT, 'urls.rest'
    DECLARE @Sobjects nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Sobjects OUT, 'urls.sobjects'
    DECLARE @Search nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Search OUT, 'urls.search'
    DECLARE @Query nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Query OUT, 'urls.query'
    DECLARE @Recent nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Recent OUT, 'urls.recent'
    DECLARE @Tooling_soap nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Tooling_soap OUT, 'urls.tooling_soap'
    DECLARE @Tooling_rest nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Tooling_rest OUT, 'urls.tooling_rest'
    DECLARE @Profile nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Profile OUT, 'urls.profile'
    DECLARE @Feeds nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Feeds OUT, 'urls.feeds'
    DECLARE @Groups nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Groups OUT, 'urls.groups'
    DECLARE @Users nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Users OUT, 'urls.users'
    DECLARE @Feed_items nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Feed_items OUT, 'urls.feed_items'
    DECLARE @Feed_elements nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Feed_elements OUT, 'urls.feed_elements'
    DECLARE @Custom_domain nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Custom_domain OUT, 'urls.custom_domain'
    DECLARE @active int
    EXEC sp_OAMethod @jResp, 'BoolOf', @active OUT, 'active'
    DECLARE @user_type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @user_type OUT, 'user_type'
    DECLARE @language nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @language OUT, 'language'
    DECLARE @locale nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @locale OUT, 'locale'
    DECLARE @utcOffset int
    EXEC sp_OAMethod @jResp, 'IntOf', @utcOffset OUT, 'utcOffset'
    DECLARE @updated_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'updated_at'
    DECLARE @is_app_installed int
    EXEC sp_OAMethod @jResp, 'BoolOf', @is_app_installed OUT, 'is_app_installed'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X GET
	-H "Content-Type: application/json"
https://login.salesforce.com{{site}}/services/oauth2/userinfo

Postman Collection Item JSON

{
  "name": "User Info",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{url}}{{site}}/services/oauth2/userinfo",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "oauth2",
        "userinfo"
      ]
    }
  },
  "response": [
    {
      "name": "Successful User Info",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{url}}{{site}}/services/oauth2/userinfo",
          "host": [
            "{{url}}{{site}}"
          ],
          "path": [
            "services",
            "oauth2",
            "userinfo"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 16 Nov 2023 15:35:50 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"sub\": \"https://login.salesforce.com/id/00D.../005...\",\n    \"user_id\": \"005...\",\n    \"organization_id\": \"00D...\",\n    \"preferred_username\": \"<username>\",\n    \"nickname\": \"<nickname>\",\n    \"name\": \"<name>\",\n    \"email\": \"<email>\",\n    \"email_verified\": true,\n    \"given_name\": \"<name>\",\n    \"family_name\": \"<name>\",\n    \"zoneinfo\": \"Europe/Paris\",\n    \"photos\": {\n        \"picture\": \"https://<file_domain>/profilephoto/005/F\",\n        \"thumbnail\": \"https://<file_domain>/profilephoto/005/T\"\n    },\n    \"profile\": \"https://<my_domain>/005\",\n    \"picture\": \"https://<file_domain>/profilephoto/005/F\",\n    \"address\": {\n        \"country\": \"FR\"\n    },\n    \"is_salesforce_integration_user\": false,\n    \"urls\": {\n        \"enterprise\": \"https://<my_domain>/services/Soap/c/{version}/00D...\",\n        \"metadata\": \"https://<my_domain>/services/Soap/m/{version}/00D...\",\n        \"partner\": \"https://<my_domain>/services/Soap/u/{version}/00D...\",\n        \"rest\": \"https://<my_domain>/services/data/v{version}/\",\n        \"sobjects\": \"https://<my_domain>/services/data/v{version}/sobjects/\",\n        \"search\": \"https://<my_domain>/services/data/v{version}/search/\",\n        \"query\": \"https://<my_domain>/services/data/v{version}/query/\",\n        \"recent\": \"https://<my_domain>/services/data/v{version}/recent/\",\n        \"tooling_soap\": \"https://<my_domain>/services/Soap/T/{version}/00D...\",\n        \"tooling_rest\": \"https://<my_domain>/services/data/v{version}/tooling/\",\n        \"profile\": \"https://<my_domain>/0052o00000DOJ1PAAX\",\n        \"feeds\": \"https://<my_domain>/services/data/v{version}/chatter/feeds\",\n        \"groups\": \"https://<my_domain>/services/data/v{version}/chatter/groups\",\n        \"users\": \"https://<my_domain>/services/data/v{version}/chatter/users\",\n        \"feed_items\": \"https://<my_domain>/services/data/v{version}/chatter/feed-items\",\n        \"feed_elements\": \"https://<my_domain>/services/data/v{version}/chatter/feed-elements\",\n        \"custom_domain\": \"https://<my_domain>\"\n    },\n    \"active\": true,\n    \"user_type\": \"STANDARD\",\n    \"language\": \"en_US\",\n    \"locale\": \"fr_FR_EURO\",\n    \"utcOffset\": 3600000,\n    \"updated_at\": \"<datetime>\",\n    \"is_app_installed\": true\n}"
    }
  ]
}