Get the latest job details using UiPath APIs

Hi @sherlin.s,

I was just setting up an example when you deleted your post so I’m going to finish responding anyways in case it helps you or someone else that stumbles on the topic.

In my environment I have ran 4 Jobs with the following start times over the last year or so.

2020-11-20T09:11:00.91Z
2020-11-20T09:12:15.387Z
2021-10-21T18:03:43.097Z
2021-10-21T18:03:44.073Z

If I run the following GET request and Parameters
{{orchestrator_url}}/{{account_name}}/{{tenant_name}}/odata/Jobs?

$filter=(ProcessType eq 'Process')&$top=10&$select=StartTime`

I get the default Sort order (Ascending)

{
    "@odata.context": "https://cloud.uipath.com/{{account_name}}/{{tenant_name}/orchestrator_/odata/$metadata#Jobs(StartTime)",
    "@odata.count": 4,
    "value": [
        {"StartTime": "2020-11-20T09:11:00.91Z"},
        {"StartTime": "2020-11-20T09:12:15.387Z"},
        {"StartTime": "2021-10-21T18:03:43.097Z"},
        {"StartTime": "2021-10-21T18:03:44.073Z"}
    ]
}

The same query but this time we will add in $orderby=StartTime asc and we get the same results in the same order.

$filter=(ProcessType eq 'Process')&$top=10&$orderby=StartTime asc&$select=StartTime
{
    "@odata.context": "https://cloud.uipath.com/{{account_name}}/{{tenant_name}}/orchestrator_/odata/$metadata#Jobs(StartTime)",
    "@odata.count": 4,
    "value": [
        {"StartTime": "2020-11-20T09:11:00.91Z"},
        {"StartTime": "2020-11-20T09:12:15.387Z"},
        {"StartTime": "2021-10-21T18:03:43.097Z"},
        {"StartTime": "2021-10-21T18:03:44.073Z"}
    ]
}

Adjusting the $orderby to descending with $orderby=StartTime desc You can see that it has reversed the order with the most recent Start time being the first value.

$filter=(ProcessType eq 'Process')&$top=10&$orderby=StartTime desc&$select=StartTime
{
    "@odata.context": "https://cloud.uipath.com/{{account_name}}/{{tenant_name}}/orchestrator_/odata/$metadata#Jobs(StartTime)",
    "@odata.count": 4,
    "value": [
        {"StartTime": "2021-10-21T18:03:44.073Z"},
        {"StartTime": "2021-10-21T18:03:43.097Z"},
        {"StartTime": "2020-11-20T09:12:15.387Z"},
        {"StartTime": "2020-11-20T09:11:00.91Z"}
    ]
}
1 Like