API Posts with Python

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"


response = requests.post(url, headers=headers, data=json_payload)

if response.status_code == 200:
    print("Data sent successfully.")
    print("Failed to send data. Status code:", response.status_code)


What kind of application did you create?

it should be confidential and redirect url should be empty

also application scope permissions are to be given

As per error looks like the permissions are missing


It’s an application that reads a mailbox and reformats the mail into more readable data.

I don’t understand how to set it to confidential.

I added the app id from the external application scope on orchestrator. I don’t know if I did it wrong.

Don’t know what else I need or need to add.
Like mentioned, I do get the bearer token. I think I’m just missing some stuff to post.

I managed to get the add queue item to work in Postman. It’s just not working when I’m trying to use it with my Python script.