AnsweredAssumed Answered

Unable to Use REST API

Question asked by ajames1234 on Jan 6, 2016
Latest reply on Dec 13, 2017 by kedster

I'm attempting to automate some maintenance and am running into an issue.


The first part of my code (Powershell) can get the Session ID:



$User = "admin"


$Password = "MASKED"


$params = @{


Uri = "";


Method = 'GET'


Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($User):$($Password)"))}


   $Session = Invoke-RestMethod -Uri $params.URI -Method $params.method -Headers $params.headers


   $sessionID = $session.session.ToString()






Once run, I get this back:




However, when I try to use that Session ID, I'm always getting "No Such Session" as a response. Am I missing something?


$URI = "$sessionID/"

$Body = @{Call='GetHostname'}

$results = Invoke-RestMethod -Uri $URI -Method GET -Body $Body