Cannot get any successful API queries after a successful authentication
EDIT: Solved - code appended below to work correctly. It was related to cookies not being passed along.
I have tried setting 'x-dell-api-version' from values of 1-7 with no success.
Here is the powershell code I have:
$body = @{
'password' = "MYPASSWORD"
'userName' = "admin"
'organizationName' = 'Default'
} | ConvertTo-Json
$Uri = 'https://MYKBOX/ams/shared/api/security/login'
$session = new-object microsoft.powershell.commands.webrequestsession
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')
$headers.Add('x-dell-api-version','5')
$Request = Invoke-WebRequest -Uri $Uri -Headers $headers -Body $body -Method Post -WebSession $session
$CSRFToken = $request.Headers.'x-dell-csrf-token'
$headers.Add("x-dell-csrf-token","$CSRFToken")
$APIUrl = 'https://MYKBOX/api/scripting/'
$rifle = Invoke-RestMethod -Uri $apiurl -Headers $headers -Method GET -WebSession $session
4 Comments
[ + ] Show comments
Answers (0)
Please log in to answer
Be the first to answer this question
Can you load /api/inventory/machines ? - chucksteel 6 years ago
{
"password" : "{{password}}",
"userName" : "{{userName}}",
"organizationName" : "Default"
}
Have you tried outputting the x-dell-csrf-token header after authentication to verify that it was returned correctly? - chucksteel 6 years ago
Essentially I added
$session = new-object microsoft.powershell.commands.webrequestsession
to my initial API authentication $request and added the -WebSession $session to it, then later on in my API call, i reused it with -WebSession $session again in the invoke-restmethod.
So essentially it was how the API needed to keep the cookies across both requests.
Thanks!! - isudothings 6 years ago