Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sAccess_token
String sId_token
String sScope
Integer iExpires_in
String sToken_type
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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}}"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "grant_type" "refresh_token" To iSuccess
Get ComUpdateString Of hoJson "client_id" "{{clientId}}" To iSuccess
Get ComUpdateString Of hoJson "refresh_token" "{{userKey}}" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://account.uipath.com/oauth/token" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI3IkpXVCIsImtpZCI6IlJUTkVOMEl5T1RWQk1UZEVRVEEzUlRZNE16UkJPVU00UVRRM016TXlSalUzUmpnMk4wSTBPQSJ9.eyJodHRwczovL3VpcGF0aC9lbWFpbCI6InJvYmVydC23YWduZXJAdWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoL2VtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2FjY291bnQudWlwYXRoLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZmZkNzhkOGNhNzk3NzAwN2JmZWEyMjYiLCJhdWQiOlsiaHR0cHM6Ly9vcmNoZXN0cmF0b3IuY2xvdWQudWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoLmV1LmF1dGgwLmNvbS91c2VyaW5mbyJdLCJpYXQiOjE2MTcxOTUxODgsImV4cCI6MTYxNzI4MTU4OCwiYXpwIjoiOERFdjFBTU5YY3pXM3k0VTE1TEwzallmNjJqSzkzbjUiLCJzY29wZSI6Im1wZW5pZCBwcm9maWxlIGVtYWlsIG9mZmxpbmVfYWNjZXNzIn0.HyycgYbs9f6EXyDRZm8w-d0A82bZqBoH594ZN-ZHujMuuoLgRF1cIq8jiAGI83P2nT4hclbVxFWiw8huPqYlu7ps9uXiiV7uKFHY2cbdEyRND1-MRYqL4HyilImy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iwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOi8vYWNjb3VudC51aXBhdGguY29tLyIsInN1YiI6ImF1dGgwfDVmZmQ3OGQ4Y2E3OTc3MDA3YmZlYTIyNiIsImF1ZCI6IjhERXYxQU1OWGN6VzN5NFUxNUxMM2pZZjYyaks5M241IiwiaWF0IjoxNjE3MTk1MTg4LCJleHAiOjE2MTcyMzExODh9.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
Get ComStringOf Of hoJResp "access_token" To sAccess_token
Get ComStringOf Of hoJResp "id_token" To sId_token
Get ComStringOf Of hoJResp "scope" To sScope
Get ComIntOf Of hoJResp "expires_in" To iExpires_in
Get ComStringOf Of hoJResp "token_type" To sToken_type
End_Procedure
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.eyJodHRwczovL3VpcGF0aC9lbWFpbCI6InJvYmVydC23YWduZXJAdWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoL2VtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2FjY291bnQudWlwYXRoLmNvbS8i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n \"token_type\": \"Bearer\"\n}"
}
]
}