I am using the following code to get auth token but getting the error , what am I doing wrong ?
import requests
import json
orchestrator_url = “UiPath”
tenant_name = “PRODTENANT”
client_id = “abcdefggh-054b-ijklmn-8387-cefbb9999999aa”
client_secret = “#3%a~k#sfadfNM3jWJ”
auth_url = f"{orchestrator_url}/{tenant_name}/api/account/authenticate"
auth_data = {
“tenancyName”: tenant_name,
“client_id”: client_id,
“client_secret”: client_secret
}
auth_headers = {
“Content-Type”: “application/json”
}
auth_response = requests.post(auth_url, headers=auth_headers, data=json.dumps(auth_data))
auth_response.raise_for_status()
auth_token = auth_response.json()[“result”]
print(auth_token)
Anil_G
(Anil Gorthi)
2
@aliyesami
the url body everything you are using is wrong…you are combining direct auth with oauth…direct auth is depricated…please follow this doc
example in postman
cheers
thanks this worked and I can get the auth token but how can I now use this token to get the folder ?
import http.client
import requests
import json
conn = http.client.HTTPSConnection(“cloud.uipath.com”)
payload = ‘grant_type=client_credentials&client_id=a3rfafa-054b-4edb-ca4x2&client_secret=#3~k#8afap34&scope=OR.Folders’
headers = {“Content-Type”: “application/x-www-form-urlencoded”}
conn.request(“POST”, “/identity_/connect/token”, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))
{“access_token”:“ENR4Wu5QqIMrUO…Y0dOzMc-GmUYq4A”,“expires_in”:3600,“token_type”:“Bearer”,“scope”:“OR.Folders”}
i tried to extract the token by doing the following but I am getting error
auth_token = res.json()[“access_token”]
AttributeError: ‘HTTPResponse’ object has no attribute ‘json’
ok i got it working …
folders_url = ‘UiPath’
folders_headers = {“Authorization”: f"Bearer {authorize_token}"}
folders_response = requests.get(folders_url, headers=folders_headers)
folders_response.raise_for_status()
folders_data = folders_response.json()[“value”]
print(json.dumps(folders_data, indent=2))