How to authenticate orchestrator API in latest version

How to authenticate orchestrator API in latest version using python. I am writing below code and getting unsupported request:

import re
import requests

Replace these values with your Orchestrator URL, tenant name, client ID, and client secret

orchestrator_url = ‘UiPath Orchestrator
tenant_name = ‘abc’
client_id = ‘xxxxxxxxxx’
client_secret = ‘xxxxxxxxxxxx’

Get authentication token

token_url = f’{orchestrator_url}/oauth/token’
token_payload = {
‘grant_type’: ‘client_credentials’,
‘client_id’: client_id,
‘client_secret’: client_secret
}

response = requests.post(token_url, data=token_payload)

print("Response is : ",response.text)

getting below response :

PS C:\Users\Python\UiPath> python .\UiPath_API_connect.py
Response is : {“error”:{“code”:“UnsupportedApiVersion”,“message”:“The HTTP resource that matches the request URI ‘UiPath Orchestrator’ does not support HTTP method ‘POST’.”,“innerError”:null}}

1 Like

have a check with swagger
also try with postman and refer afterwards to the Curl fromPostman

Let us know:

  • Orchestrator Edition (on-prem,…)
  • Orchestrator version
  • swagger version

Thanks

1 Like

It is cloud version

Orc version : Latest (2023)
swagger version : 18.0

@Sumit_Ghosh1,

If you are using UiPath Cloud then follow this Postman collection for Authentication.

https://www.postman.com/uipath/workspace/uipath-s-public-workspace/folder/15161494-16daae6b-bce5-4fff-b623-eb4ffb0d1a71

Thanks,
Ashok :slight_smile:

we recommend using the current state of the art methods e.g. OAuth2

It doesnt work as authentication is not working. Need help on what is the endpoint of the authentication /headers to be passed to get the bearer token

@Sumit_Ghosh1,

Here are the specific header details:
Access Token URL: https://cloud.uipath.com/identity_/connect/token

Thanks,
Ashok :slight_smile:

Unable to edit anything. Getting below after run:

@Sumit_Ghosh1


    def __init__(
        self,
        client_id: str,
        refresh_token: str,
        base_url: str,
        tokenurl="https://account.uipath.com/oauth/token",
    ):
        """
        Initialize the API client.

        Parameters:
        client_id (str): The client ID for the API.
        refresh_token (str): The refresh token for the API.
        base_url (str): The base URL for the API.
        token_url (str): The URL to get the token from. Defaults to "https://account.uipath.com/oauth/token".
        """

        token_url = tokenurl
        self.base_url = base_url

        body = {
            "grant_type": "refresh_token",
            "client_id": client_id,
            "refresh_token": refresh_token,
        }

        headers = {"Authorization": "Bearer", "Content-Type": CONTENT_TYPE_JSON}

        response = requests.post(token_url, json=body, headers=headers)

        access = response.json()
        if response.status_code == 200:
            self.access_token = access["access_token"]
        else:
            raise ValueError(
                f"Failed to retrieve access token. Status code: {str(response.status_code)}. Response: {response.text}"
            )

I have this method in an existing code try this you will have to edit out somethings like base url

I think you are using class. can you post the whole code on how you are autheticating. Also, what is the refresh token ?

It seems you are using oAuth(which is depreceated).

refresh token you will find in the admin panel of orchestrator under API access.

here is the whole code

I do not see any refresh token under admin panel → Services → Orchestrator → API access;

image

refresh token is your user key

we shared with you the link for setting up the external application, had you done so far?

Hi @Sumit_Ghosh1

Maybe you could try like this.
UiPath Cloud----Admin----External Applications----Add Application Under OAuth Apps, you can get APP ID and APP Secret, APP ID is POSTMAN’S Client ID, APP Secret is POSTMAN’S Client Secret, others argument just like you have filled.

BR,
Donghai