Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Access_token
string ls_Id_token
string ls_Scope
integer li_Expires_in
string ls_Token_type
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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}}"
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("grant_type","refresh_token")
loo_Json.UpdateString("client_id","{{clientId}}")
loo_Json.UpdateString("refresh_token","{{userKey}}")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Resp = loo_Http.PostJson3("https://account.uipath.com/oauth/token","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI3IkpXVCIsImtpZCI6IlJUTkVOMEl5T1RWQk1UZEVRVEEzUlRZNE16UkJPVU00UVRRM016TXlSalUzUmpnMk4wSTBPQSJ9.eyJodHRwczovL3VpcGF0aC9lbWFpbCI6InJvYmVydC23YWduZXJAdWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoL2VtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2FjY291bnQudWlwYXRoLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZmZkNzhkOGNhNzk3NzAwN2JmZWEyMjYiLCJhdWQiOlsiaHR0cHM6Ly9vcmNoZXN0cmF0b3IuY2xvdWQudWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoLmV1LmF1dGgwLmNvbS91c2VyaW5mbyJdLCJpYXQiOjE2MTcxOTUxODgsImV4cCI6MTYxNzI4MTU4OCwiYXpwIjoiOERFdjFBTU5YY3pXM3k0VTE1TEwzallmNjJqSzkzbjUiLCJzY29wZSI6Im1wZW5pZCBwcm9maWxlIGVtYWlsIG9mZmxpbmVfYWNjZXNzIn0.HyycgYbs9f6EXyDRZm8w-d0A82bZqBoH594ZN-ZHujMuuoLgRF1cIq8jiAGI83P2nT4hclbVxFWiw8huPqYlu7ps9uXiiV7uKFHY2cbdEyRND1-MRYqL4HyilImyJFuIREwYyl1NHshKWZ1GYepIkX6plKTT2zAXEOZ68hfb22loSQld0uGi6X9eV6sCiSV8RCLF0qMp9Pi6SzQxx3OwYJXZJWnhTlRGWUbvvBw7E0s7nJKPMKFyqiMQUu8fXYdl_zKPlEFhf-MnOo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QU1OWGN6VzN5NFUxNUxMM2pZZjYyaks5M241IiwiaWF0IjoxNjE3MTk1MTg4LCJleHAiOjE2MTcyMzExODh9.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
ls_Access_token = loo_JResp.StringOf("access_token")
ls_Id_token = loo_JResp.StringOf("id_token")
ls_Scope = loo_JResp.StringOf("scope")
li_Expires_in = loo_JResp.IntOf("expires_in")
ls_Token_type = loo_JResp.StringOf("token_type")
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
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.eyJodHRwczovL3VpcGF0aC9lbWFpbCI6InJvYmVydC23YWduZXJAdWlwYXRoLmNvbSIsImh0dHBzOi8vdWlwYXRoL2VtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2FjY291bnQudWlwYXRoLmNvbS8iLCJzdWIiOiJhdXRoMHw1ZmZkNzhkOGNhNzk3NzAwN2JmZWEyMjYiLCJhdWQiOlsiaHR0cHM6Ly9vcmNoZXN0cmF0b3IuY2xvdWQudWlwYXRoLmNvbSI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6InJvYmVydC53YWduZXIiLCJuYW1lIjoicm9iZXJ0LndhZ25lckB1aXBhdGguY29tIiwicGljdHVyZSI1Imh0dHBzOi8vcy5ncmF2YXRhci5jb20vYXZhdGFyLzc5ZWI3OTM1ZDBjZDczYzZlNWVmMThiNTM5Y2JmY2M0P3M9NDgwJnI9cGcmZD1odHRwcyUzQSUyRiUyRmNkbi5hdXRoMC5jb20lMkZhdmF0YXJzJTJGcm8ucG5nIiwidXBkYXRlZF9hdCI6IjIwMjEtMDMtMzFUMTI6MjA6MTYuOTM2WiIsImVtYWlsIjoicm9iZXJ0LndhZ25lckB1aXBhdGguY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOi8vYWNjb3VudC51aXBhdGguY29tLyIsInN1YiI6ImF1dGgwfDVmZmQ3OGQ4Y2E3OTc3MDA3YmZlYTIyNiIsImF1ZCI6IjhERXYxQU1OWGN6VzN5NFUxNUxMM2pZZjYyaks5M241IiwiaWF0IjoxNjE3MTk1MTg4LCJleHAiOjE2MTcyMzExODh9.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}"
}
]
}