Triggering Orchestrator from Powershell

Hello everyone,

I am trying to launch my bot after a SQL job has completed and calls a Powershell script. I can get the token, but the syntax on start job is confusing me as I’m not very familiar with PS.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$postBody = @{startInfo{ReleaseKey=‘ourReleaseKey’;Strategy=‘Specific’;RobotIds=[8];NoOfRobots=0;Source=‘Manual’}}
$headers = @{ContentType=‘application/json’;Authorization=(‘Bearer’ + $token)}
$response = Invoke-WebRequest -Uri -Method POST -Body $postBody -Headers $headers | ConvertFrom-Json;

I believe the issue is the double {{}} at startInfo, or maybe the way RobotIds is declared, any guidance is appreciated.

The working JSON looks like this,


How do I convert this to PS correctly?

I too Stuck with this same issue !!!.. Anyone help us to solve this …

Definitely too late Bala on replying to this one sorry but for all future readers,

The issue was simply how the header was being declared, if you create the dictionary object of string, string first,
$headers1 = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”

Then add the tokens like this, $headers1.Add(“Authorization”, “$token”) | ConvertTo-Json

So a final Powershell rest call may look like,
(Get a token)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$postBody = @{tenancyName=‘’;usernameOrEmailAddress=‘userName’;password=‘Password’}
$headers = @{ContentType=‘application/json’}
$response = Invoke-WebRequest -Uri https://yoururl/api/account/authenticate -Method POST -Body $postBody -Headers $headers | ConvertFrom-Json;
$token = ('Bearer ’ + $response.result );

(Start the bot)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$postBody1 = ‘{“startInfo”:{“ReleaseKey”:“yourReleasekey”,“Strategy”:“Specific”,“RobotIds”:[11],“NoOfRobots”:0,“Source”:“Manual”}}’
$headers1 = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers1.Add(“Authorization”, “$token”) | ConvertTo-Json
$response1 = Invoke-RestMethod -Uri https://yourURL/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs -Method POST -ContentType ‘application/json’ -Headers $headers1 -Body $postBody1;

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.