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
DECLARE @iTmp0 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
-- Adds the "Authorization: Bearer {{accessToken}}" header.
EXEC sp_OASetProperty @http, 'AuthToken', '{{accessToken}}'
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://{{hostenv}}/oauth/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
EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT
PRINT 'Response status code = ' + @iTmp0
EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
END
GO
Curl Command
curl -X GET
-H "Authorization: Bearer {{accessToken}}"
https://{{hostenv}}/oauth/userinfo
Postman Collection Item JSON
{
"name": "04 Get User Info",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"var accounts = jsonData.accounts;",
"if (jsonData.hasOwnProperty(\"sub\")) { ",
" postman.setEnvironmentVariable(\"userId\", jsonData.sub); ",
"} ",
"",
"for (var i=0; i< accounts.length; i++) { ",
" if (accounts[i].hasOwnProperty(\"is_default\")) { ",
" if (accounts[i].is_default === true) { ",
" postman.setEnvironmentVariable(\"accountId\", accounts[i].account_id); ",
" postman.setEnvironmentVariable(\"baseUrl\", accounts[i].base_uri + \"/restapi/\"); ",
" postman.setEnvironmentVariable(\"accountName\", accounts[i].account_name); ",
" } ",
" } ",
"} ",
""
]
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{accessToken}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "https://{{hostenv}}/oauth/userinfo",
"protocol": "https",
"host": [
"{{hostenv}}"
],
"path": [
"oauth",
"userinfo"
]
}
},
"response": [
]
}