How to use Orchestrator API?

Hello,

I want to call Orchestrator 2020’s API with a single python script.
I readed documentation here :
Consuming Cloud API
Authenticating

I have completed all the steps described :

I tried both examples in links above :

  • Consuming Cloud API
import requests

urlAuth = "https://account.uipath.com/oauth/token"

jsonAuth = {
    "grant_type": "refresh_token",
    "client_id": clientID,
    "refresh_token": userKey
}

headerAuth = {
    'X-UIPATH-TenantName': tenantName,
    'Content-Type': 'application/json'
}

response = requests.post(urlAuth, data=jsonAuth, headers=headerAuth)

print(response)

Result :

<Response [400]>
  • Authenticating
import requests

urlAuth = "https://cloud.uipath.com/" + accountLogicalName + "/" + tenantName + "/api/account/authenticate"

jsonAuth = {
    "tenancyName": tenantName,
    "usernameOrEmailAddress": mail,
    "password": password
}

headerAuth = {
    'Content-Type': 'application/json'
}

response = requests.post(urlAuth, data=jsonAuth, headers=headerAuth)

print(response)

Result :

<Response [400]>

I always got a failed response (400). Nothing else is explained on links above. Can someone help me ?

Regards.

Did u made configuration in orchestrator regarding API call?

I didn’t see any information about specific API configuration on Orchestrator. Do you think about something ?

I have Community Studio and Cloud Orchestrator.

You can use this link as reference. Postman UiPath Rocks

Hi @Maxime_Bonis

U can check this video for configurations

Thank you for the link it will help me for the continuation of my API tests.

But concerning the connection to my orchestrator it confirms that my code is good. But there is always a 400 response.

This video just configures the right of the robot as administrator to be able to launch a process with this same robot.

It’s not a good security practice and beyond that it doesn’t solve my API call problem from Python (so external to UiPath).

But thanks for proposing a solution.

Hi @Maxime_Bonis

I think it without configuring it u can’t access the data using orchestrator API .

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed::relaxed:

Okay, guys. I located the problem a line in my header had ( ’ ) instead of ( " ).
Here’s the code:

urlAuth = "https://account.uipath.com/oauth/token"

data = {
    "grant_type": "refresh_token",
    "client_id": clientID,
    "refresh_token": userKey
}

header = {
    "Content-Type": "application/json",
    "X-UIPATH-TenantName": tenantName
}

r = requests.post(urlAuth, data, header)

response = json.loads(r.content)
auth = "Bearer " + response["access_token"]

I know that now I have to call Folders first, to get my FolderId that corresponds to “X-UIPATH-OrganizationUnitId”.

Then, I have to call Releases, to get the Id of my target process which corresponds to ‘ReleaseKey’.

Finally, I need to call UiPath.Server.Configuration.OData.StartJobs to launch the job I want. Nothing very complicated.

However, I can’t call the endpoint Folders. The documentation is awful. Here’s all informations I have about Folders to show you what I mean by “awful” :slight_smile:

I got the Folder call information here :

This is Folder doc in API doc :


Note that the URL is not the right one. And the authorization is marked SEPARATE from the header.
Moreover, it is not specified if the authorization is a JSON, nor the key, if it is a String, if it contains keywords, its format…

Then I search information by my-self :

https://docs.uipath.com/orchestrator/v0/reference/folders-requests

This is what I get, 2 end point that don’t correspond at all to what I’m looking for, nor to what the API doc shows. In addition, this time we have information about the authorization which is probably a String, remember well.

Finally, I looked at the sample code from the video (Start UiPath Process from Python (Script Code REST API) | Python call UiPath Job - YouTube), which doesn’t really explain how to get the release key for the process he wants to launch. However in his code he has an example of the authorization token:

headers2 = { "Content-Type" : "application/json",
             "X-UIPATH-TenantName" : "YOUR TENANTNAME",
			 "Authorization" : auth}

So here the authorization is IN the header.

So you understand my suffering trying to understand the Uipath API.
Help me to launch a simple process (call of Folders, then Releases, then UiPath.Server.Configuration.OData.StartJobs) and I will put in this post the complete and very simple python code so that other people in my situation will have a quick and easy to understand solution.

Thank you so much,
Regards.

Hello Maxime,
Here you have Video where I start UiPath Process from Python (full code is in the description of the movie) :

Thanks,
Cristian Negulescu

Please read all the topic before posting… Are you a bot ?

I’m not a BOT but I Read this sTuff:
I want to call Orchestrator 2020’s API with a single python script

Hello @Maxime_Bonis,

In fact, the UiPath Orchestrator API documentation needs to get some improvements/updates. I know that they launched this new API recently and some of the documentation is still reflecting the old methods, hence causing some confusion.

I would say you already cracked the main issues so you should be able to make it work easily.

About the authorization, it must be passed as a Header in every single request (except for the Auth), with the format:
“Authorization”: “Bearer [access_token]”

The reason why the Authorization is separate from the Headers is due to the fact that the documentation is generated from Postman, where the Authorization is indeed shown in a separate tab, even though during the request is being included in the Headers.

In this link: Consuming Cloud API
The documentation is updated and it says that you should always use https://cloud.uipath.com/[Account Logical Name]/[Tenant Name] (except for auth), in the other sections from Docs it might show you the old way.

I recommend you to ‘Run in Postman’ the APIs. As far as I tested, they’re built properly and you can test them, before creating the logic in Python.

So, keeping in mind that your headers must include, at least:

  • X-UiPATH-TenantName
  • Authorization

URL = https://cloud.uipath.com/[Account Logical Name]/[Tenant Name]

  1. Authenticate: https://account.uipath.com/oauth/token (to get the refresh token)
  2. Get Folders: URL/odata/Folders (get folder ID)
  3. Get Releases by name: URL/odata/Releases?$filter=ProcessKey eq ‘Heyyo’ (to get release key)
  4. Start Job: URL/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs

My last tip: in the Postman API documentation (that you show in a screenshot in your comment), change the language to Python, so you can see the code properly, BUT check the fields described on the left side (white part), not in the code example, since as you noticed, those aren’t correct (old version).

Let me know if this was helpful or if you need something else.

Here is few my samples - it’s working full on API so you have to study it Authenticator_cloud.xaml (11.0 KB) WhoAmI.xaml (13.0 KB)

Hello,

Sorry for the long time response.
It didn’t work with the correct header :

print(auth)
print(urlFolders)
print(tenantName)
header = {
    "Content-Type": "application/json",
    "X-UIPATH-TenantName": tenantName,
    "Authorization": auth
}

r = requests.post(urlFolders, header)

response = json.loads(r.content)
print(response)

console :

Bearer eyJhbGciOiJSUzI1...
https://platform.uipath.com/odata/Folders
Datap...
{'message': 'You are not authenticated!', 'errorCode': 0, 'result': None, 'targetUrl': None, 'success': False, 'error': {'code': 0, 'message': 'You are not authenticated!', 'details': 'You should be authenticated (sign in) in order to perform this operation.', 'validationErrors': None}, 'unAuthorizedRequest': True, '__abp': True}

Is API accessible to Community account ?

Hello @Maxime_Bonis,

Yes, it is.

Your endpoint/URL is incorrect.
The urFolders should include: https://cloud.uipath.com/[Account Logical Name]/[Tenant Name]/odata/Folders
You can take the Account Logical Name and Tenant Name from your API info.

Apart of that, everything seems to be correct.

1 Like

Still the same :

print(auth)
print(tenantName)
urlFolders += accountLogicalName + "/" + tenantName + "/odata/Folders"
print(urlFolders)
header = {
    "Content-Type": "application/json",
    "X-UIPATH-TenantName": tenantName,
    "Authorization": auth
}

r = requests.post(urlFolders, header)

response = json.loads(r.content)
print(response)

Console :

Bearer eyJhbGciOiJSU...
Dat...ult
https://cloud.uipath.com/dat...mqa/Dat...ult/odata/Folders
{'message': 'You are not authenticated!', 'errorCode': 0, 'result': None, 'targetUrl': None, 'success': False, 'error': {'code': 0, 'message': 'You are not authenticated!', 'details': 'You should be authenticated (sign in) in order to perform this operation.', 'validationErrors': None}, 'unAuthorizedRequest': True, '__abp': True}

Process finished with exit code 0

Do you want to make a call with me one day to see together where is my error ?