Unable to pull jobs

please see the code below for Jobs and Folders , I can pull the Folders fine but for Jobs iam getting error "HTTPError: 400 Client Error: Bad request.
So if i replace “Jobs” with “Folders” in below code I get all the folders.
how can I get it to run for jobs?

++++++++++ JOBS ++++++++++++
import http.client
import requests
import json

conn = http.client.HTTPSConnection(“cloud.uipath.com”)
jobs_payload = ‘grant_type=client_credentials&client_id=b8b50cdc-054b-4edb-8387-xxxxxxxxxx&client_secret=#3~k#6xxxxxxxxx&scope=OR.Jobs’

#---- get the auth token
headers = {“Content-Type”: “application/x-www-form-urlencoded”}
conn.request(“POST”, “/identity_/connect/token”, jobs_payload, headers)
res = conn.getresponse()
data = res.read()
res_dict = json.loads(data.decode(‘utf-8’))
authorize_token=res_dict.get(‘access_token’)

#— retrieve jobs -------------
jobs_url =‘UiPath
jobs_headers = {“Authorization”: f"Bearer {authorize_token}"}
jobs_response = requests.get(jobs_url, headers=jobs_headers)
jobs_response.raise_for_status()
jobs_data = jobs_response.json()[“value”]
print(json.dumps(jobs_data, indent=2))

@aliyesami

For jobs you need to add X-UiPath-OrganizationUnitId in the header and value should be one of the folder id

Cheers

can you please guide me more? where can I find “X-UiPath-OrganizationUnitid” ?
and what If i want to pull all the jobs dynamically in an ETL ? I dont have folder ids and I am asked to get all the jobs in UiPath via API

Log into Orchestrator and go to any folder. The value to use for X-UiPath-OrganizationUnitId will be the tid value in the URL.

ok I am trying to use the following url for getting all the jobs ran by a particular Robot but its giving me syntax error, I got this syntax from the UI documentation

UiPath eq ‘RPA PrdUser1’

I am following this doc
https://{yourDomain}/odata/Jobs?$top=10&$filter=Robot/Name eq ‘DocBot’

it won’t let me type the URL in readable format it collapses it automatically, but you can copy the url to get the format

if i goto any folder I get the same tid value …is that normal?

folders?tid=23572

see there is something fundamentally I am missing . The API URL in my code though working for Folders does not accept this syntax which also apparently is API I am seeing all over web .

Yes because they’re all in the same org. That’s the point.

Have you looked at Swagger to see how to format the API calls? And why are you doing this with code instead of the Orchestrator HTTP Request activity? If you use the activity you don’t have to worry about manually authenticating.

https://yourdomain/swagger/index.html

I have to do it in code as we have external job that runs on AWS Glue.
I am not understanding why this syntax is not working for me and how can I correct it?
like i pointed out that the API syntax I am using is correct for Folders so how can I write it to pull jobs based on the following document ?

The syntax isn’t the same for all methods, which is why I suggested looking at Swagger because it gives you the syntax for each method.

@aliyesami

Ypu might be getting from old doc as well…please check swagger

<orchestratorurl/swagger/index.html is the url you can use to get the swagger…in tht you would have the full syntax you can try as well

Cheers

ok I used the swagger/index.html for jobs and choose the "execute " option to see what urls it generates and its generating the url that i already had mentioned in the post and its not working .

btw the above syntax from swagger works for folders , so for jobs there has to be something i am missing in the url if someone can kindly point that out.

Something that just hit me, when doing this with Orchestrator HTTP Request it’s folder-specific. Whatever folder you’re connected to in Studio, you’ll get just the jobs for that folder. If I’m trying to get all jobs for all folders, I’d have to first get all the folders, then loop through them and do the job query for each folder. I wonder if you have to do something similar using an external HTTP request. The job property OrganizationUnitId is the id (integer) of the folder the Job ran in.

This post seems relevant.

ok thats fine , I have the folders , can you please give me the API syntax or getting all the jobs for a particular folder?

Fairly old but I’m guessing it still applies.

There is other info in that thread about what you’re trying to do.

I am sorry but I am not seeing anywhere in the post how to construct this API call , can you point it? where in the jobs_payload or jobs_url I need to specify the folder for which I am looking for jobs?

jobs_payload = ‘grant_type=client_credentials&client_id=b8b50c&client_secret=xyz&scope=OR.Jobs’

jobs_url = ‘https://cloud.uipath.com/xxx/PROD_UIPATH/orchestrator_/odata/Jobs’