Problems using authentication token to get robot information from Orchestrator using powershell


#1

Hi

I am trying to use the Invoke-RestMethod in powershell to authenticate and get information about robots. I can authenticate successfully and get a result token by when using the token to get information I get the following error fro the orchestrator server

Invoke-RestMethod : {“result”:null,“targetUrl”:null,“success”:false,“error”:{“code”:0,“message”:“You are not authenticated!”,“details”:“You should be authenticated
(sign in) in order to perform this operation.”,“validationErrors”:null},“unAuthorizedRequest”:true,"__abp":true}

Can anyone point me in the right direction? Here is my code.

$logon = @{
    tenancyName='name'
    usernameOrEmailAddress='username'
    password='password'
}
$json = $logon | ConvertTo-Json
$response = Invoke-RestMethod 'https://academy2016.uipath.com/api/account/authenticate' -Method Post -Body $json -ContentType 'application/json' -ProxyUseDefaultCredentials -Proxy 'http://proxy:8080'
Write-Output = $response.result

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", 'Bearer ZUpy8eviPyg8sigTPYDBmE9ahZ_hPl35GYLepN3uf34cwQcJUDjDWZN2dTAy5XIxtoSR-3I2cdQUXigUNJfSUdWJK2fex5s7WFSAraMVAASe9H0DeYW3iNFGdhyyUNQKTM1rA5TCo9oBetK_D29rNVfqDFWL69f2ym6gjiJ ZSbB_DKkubOgy6DYdJe4NUls92vOM7LKk3o1APa-wVYgJ9hNrEJihtYpX-5pxZQVN5594R8LI6qhldfuSnNLRNPQAQFB68tI_0d2qrWZ3hwfTYHFZ1b6YpPsw1WmLfSQn-3tIYY3WOnXyfJ8k9PiyS12uQ7i85k0aeB9L69 OIMLvpqUZVF57y378KYCHu0v6GNP7BOngrGcrM8WcY_51PKJAXR-meF35v8CpqRE9dOEDfClpRWCxFex9WZrC6oGM9EmnBilYncaDmY8-uflmFyeY9nQJ1HB0FOqwPctPD1BeKgaXNHyRjhaDSToo9aeOymPlZigEOxFY4- YZ22KiegS8ukGVTpg')
$response = Invoke-RestMethod 'https://academy2016.uipath.com/odata/Robots' -Headers $headers -ProxyUseDefaultCredentials -Proxy 'http://proxy:8080'