I’m trying to use Python (in VSCode) to get the bearer token and then using the bearer token and a json payload to post items into a key using the AddQueueItem call.
I am getting the bearer token, but when I try to post the content, I receive a 403 error response.
I did add an external application (although I couldn’t specify it to be Python or VSCode), and I am sending the ApplicationID in the header. Is there something I’m doing wrong?
Here is my code:
itemData = {
"Name": "testAPI",
"Priority": "Normal",
"SpecificContent": {
"Event Date": "Date Test",
"Record Time": "Time Test",
"Event Number": "Num Test",
"Download Event": "Download Test",
"Query Event": "Query Test",
},
"Reference": "Num Test",
"Source": "Manual",
}
json_payload = json.dumps(itemData)
client_id = "my client id"
client_secret = "my client secret"
token_url = "https://cloud.uipath.com/identity_/connect/token"
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url, client_id=client_id, client_secret=client_secret)
application_id = "app id"
url = "{my orchestrator url}/odata/Queues/UiPathODataSvc.AddQueueItem"
headers = {
"Authorization": f"Bearer {token['access_token']}",
"X-UIPATH-OrganizationUnitId": application_id,
"Content-Type": "application/json"
}
print(headers)
response = requests.post(url, headers=headers, data=json_payload)
if response.status_code == 200:
print("Data sent successfully.")
else:
print("Failed to send data. Status code:", response.status_code)