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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "grant_type": "refresh_token",
-- "client_id": "{{clientId}}",
-- "refresh_token": "{{userKey}}"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'grant_type', 'refresh_token'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'client_id', '{{clientId}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'refresh_token', '{{userKey}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://account.uipath.com/oauth/token', 'application/json', @json
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 @json
RETURN
END
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 @resp, 'GetBodySb', @success OUT, @sbResponseBody
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 @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI3IkpXVCIsImtpZCI6IlJUTkVOMEl5T1RWQk1UZEVRVEEzUlRZNE16UkJPVU00UVRRM016TXlSalUzUmpnMk4wSTBPQSJ9.eyJodHRwczovL3VpcGF0aC9lbWFpbCI6InJvYmVydC23YWduZXJAdWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoL2VtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2FjY291bnQudWlwYXRoLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZmZkNzhkOGNhNzk3NzAwN2JmZWEyMjYiLCJhdWQiOlsiaHR0cHM6Ly9vcmNoZXN0cmF0b3IuY2xvdWQudWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoLmV1LmF1dGgwLmNvbS91c2VyaW5mbyJdLCJpYXQi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ljdHVyZSI1Imh0dHBzOi8vcy5ncmF2YXRhci5jb20vYXZhdGFyLzc5ZWI3OTM1ZDBjZDczYzZlNWVmMThiNTM5Y2JmY2M0P3M9NDgwJnI9cGcmZD1odHRwcyUzQSUyRiUyRmNkbi5hdXRoMC5jb20lMkZhdmF0YXJzJTJGcm8ucG5nIiwidXBkYXRlZF9hdCI6IjIwMjEtMDMtMzFUMTI6MjA6MTYuOTM2WiIsImVtYWlsIjoicm9iZXJ0LndhZ25lckB1aXBhdGguY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOi8vYWNjb3VudC51aXBhdGguY29tLyIsInN1YiI6ImF1dGgwfDVmZmQ3OGQ4Y2E3OTc3MDA3YmZlYTIyNiIsImF1ZCI6IjhERXYxQU1OWGN6VzN5NFUxNUxMM2pZZjYyaks5M241IiwiaWF0IjoxNjE3MTk1MTg4LCJleHAiOjE2MTcyMzExODh9.F4GrdXgZyPHrK9WQGVjIQx2nPx6tibbZK-SRRIhM85sCAy3F6FDF9ip_dWxR3t9XSVAa-kCrapzOitTnDgW_USCKTt_9ICZOOvq1UTvuXx0uFCjxYM78x3dZPpyE_LUNaBtlEc7c67xrgbPswA6fdyueehsEzJVdt_c9CQSBOflq8vRrElmr5Sk7qsf3RNYQ1u5vG12S-jtjJCnJKBxijK69SPENRVoiFxSBTneS28m53knMbTkhx48a4aTmuhl4QeLlWrFqzfJ7x8iE1TrNXCyaF5mr57s1wXlLA08y8jwHTxy0bQ0EYCYowtFr0iGnNKTZaRcuiCOp4K5wpi2VsZ",
-- "scope": "openid profile email offline_access",
-- "expires_in": 86400,
-- "token_type": "Bearer"
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @access_token nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @access_token OUT, 'access_token'
DECLARE @id_token nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @id_token OUT, 'id_token'
DECLARE @scope nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @scope OUT, 'scope'
DECLARE @expires_in int
EXEC sp_OAMethod @jResp, 'IntOf', @expires_in OUT, 'expires_in'
DECLARE @token_type nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @token_type OUT, 'token_type'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X POST
-H "Content-Type: application/json"
-d '{
"grant_type": "refresh_token",
"client_id": "{{clientId}}",
"refresh_token": "{{userKey}}"
}'
https://account.uipath.com/oauth/token
Postman Collection Item JSON
{
"name": "Authenticate (Cloud)",
"event": [
{
"listen": "test",
"script": {
"exec": [
"//test status code\r",
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"//set access token\r",
"var jsonData = JSON.parse(responseBody);\r",
"pm.environment.set(\"token\", jsonData.access_token);\r",
"console.log(pm.environment.get(\"token\"));\r",
"\r",
"//check if access token is available\r",
"pm.test(\"Property Access Token available\", function () {\r",
" pm.expect(pm.response.text()).to.include(\"access_token\");\r",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"grant_type\": \"refresh_token\",\r\n \"client_id\": \"{{clientId}}\",\r\n \"refresh_token\": \"{{userKey}}\"\r\n}"
},
"url": {
"raw": "https://account.uipath.com/oauth/token",
"protocol": "https",
"host": [
"account",
"uipath",
"com"
],
"path": [
"oauth",
"token"
]
},
"description": "**FOR CLOUD ORCHESTRATOR USERS**\n\nThe first step is to send Orchestrator your **_Client ID_** and **_User Key_** so it knows who is making these calls. Orchestrator will return a token that authenticates all subsequent actions.\n\nHTTP Header: `Authorization`: Bearer {token}\n\nRead how to get your **_Client ID_** and **_User Key_** \n[ here](https://docs.uipath.com/orchestrator/reference/consuming-cloud-api)."
},
"response": [
{
"name": "Authenticate (Cloud)",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"grant_type\": \"refresh_token\",\r\n \"client_id\": \"{{clientId}}\",\r\n \"refresh_token\": \"{{userKey}}\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://account.uipath.com/oauth/token",
"protocol": "https",
"host": [
"account",
"uipath",
"com"
],
"path": [
"oauth",
"token"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Wed, 31 Mar 2021 12:53:08 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "CF-Ray",
"value": "6389b803ca690d5a-VIE"
},
{
"key": "Cache-Control",
"value": "no-store"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000"
},
{
"key": "Vary",
"value": "Accept-Encoding, Origin"
},
{
"key": "CF-Cache-Status",
"value": "DYNAMIC"
},
{
"key": "cf-request-id",
"value": "0929f1566200000d5a19998000000001"
},
{
"key": "Expect-CT",
"value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
},
{
"key": "ot-baggage-auth0-request-id",
"value": "6389b803ca690d5a"
},
{
"key": "ot-tracer-sampled",
"value": "true"
},
{
"key": "ot-tracer-spanid",
"value": "5291a51954262f0f"
},
{
"key": "ot-tracer-traceid",
"value": "5ee3eb847f96f83f"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "X-Auth0-RequestId",
"value": "f21fde3857e0375b0bfe"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-RateLimit-Limit",
"value": "1000000"
},
{
"key": "X-RateLimit-Remaining",
"value": "999999"
},
{
"key": "X-RateLimit-Reset",
"value": "1617195188"
},
{
"key": "Server",
"value": "cloudflare"
},
{
"key": "Content-Encoding",
"value": "br"
},
{
"key": "alt-svc",
"value": "h3-27=\":443\"; ma=86400, h3-28=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"
}
],
"cookie": [
],
"body": "{\n \"access_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI3IkpXVCIsImtpZCI6IlJUTkVOMEl5T1RWQk1UZEVRVEEzUlRZNE16UkJPVU00UVRRM016TXlSalUzUmpnMk4wSTBPQSJ9.eyJodHRwczovL3VpcGF0aC9lbWFpbCI6InJvYmVydC23YWduZXJAdWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoL2VtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2FjY291bnQudWlwYXRoLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZmZkNzhkOGNhNzk3NzAwN2JmZWEyMjYiLCJhdWQiOlsiaHR0cHM6Ly9vcmNoZXN0cmF0b3IuY2xvdWQudWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoLmV1LmF1dGgwLmNvbS91c2VyaW5mbyJdLCJpYXQiOjE2MTcxOTUxODgsImV4cCI6MTYxNzI4MTU4OCwiYXpwIjoiOERFdjFBTU5YY3pXM3k0VTE1TEwzallmNjJqSzkzbjUiLCJzY29wZSI6Im1wZW5pZCBwcm9maWxlIGVtYWlsIG9mZmxpbmVfYWNjZXNzIn0.HyycgYbs9f6EXyDRZm8w-d0A82bZqBoH594ZN-ZHujMuuoLgRF1cIq8jiAGI83P2nT4hclbVxFWiw8huPqYlu7ps9uXiiV7uKFHY2cbdEyRND1-MRYqL4HyilImyJFuIREwYyl1NHshKWZ1GYepIkX6plKTT2zAXEOZ68hfb22loSQld0uGi6X9eV6sCiSV8RCLF0qMp9Pi6SzQxx3OwY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ImF1dGgwfDVmZmQ3OGQ4Y2E3OTc3MDA3YmZlYTIyNiIsImF1ZCI6IjhERXYxQU1OWGN6VzN5NFUxNUxMM2pZZjYyaks5M241IiwiaWF0IjoxNjE3MTk1MTg4LCJleHAiOjE2MTcyMzExODh9.F4GrdXgZyPHrK9WQGVjIQx2nPx6tibbZK-SRRIhM85sCAy3F6FDF9ip_dWxR3t9XSVAa-kCrapzOitTnDgW_USCKTt_9ICZOOvq1UTvuXx0uFCjxYM78x3dZPpyE_LUNaBtlEc7c67xrgbPswA6fdyueehsEzJVdt_c9CQSBOflq8vRrElmr5Sk7qsf3RNYQ1u5vG12S-jtjJCnJKBxijK69SPENRVoiFxSBTneS28m53knMbTkhx48a4aTmuhl4QeLlWrFqzfJ7x8iE1TrNXCyaF5mr57s1wXlLA08y8jwHTxy0bQ0EYCYowtFr0iGnNKTZaRcuiCOp4K5wpi2VsZ\",\n \"scope\": \"openid profile email offline_access\",\n \"expires_in\": 86400,\n \"token_type\": \"Bearer\"\n}"
}
]
}