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
DECLARE @req int
-- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT
DECLARE @jsonParam1 int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonParam1 OUT
EXEC sp_OAMethod @jsonParam1, 'Emit', @sTmp0 OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'refresh_token', @sTmp0
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Authorization', 'Basic {{encodedKeys}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://{{hostenv}}/oauth/token', @req
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @req
EXEC @hr = sp_OADestroy @jsonParam1
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @req
EXEC @hr = sp_OADestroy @jsonParam1
END
GO
Curl Command
curl -X POST
-H "Authorization: Basic {{encodedKeys}}"
--data-urlencode 'refresh_token={{refreshToken}}'
https://{{hostenv}}/oauth/token
Postman Collection Item JSON
{
"name": "03 Refresh Access Token",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"accessToken\", jsonData.access_token);",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"refreshToken\", jsonData.refresh_token);"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Basic {{encodedKeys}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "refresh_token",
"value": "{{refreshToken}}"
}
]
},
"url": {
"raw": "https://{{hostenv}}/oauth/token",
"protocol": "https",
"host": [
"{{hostenv}}"
],
"path": [
"oauth",
"token"
]
}
},
"response": [
]
}