Invoke-RestMethod and "Not Logged In" error

Hi all,
I’m struggling automating a change on the Netscaler using REST API. When I use Invoke-RestMethod to do “PUT” operation I get a strange error: Invoke-RestMethod : { “errorcode”: 1026, “message”: “Not logged in”, “severity”: “ERROR” }
This operation with the same body and using the same account executed from Postman works OK, so it’s not an issue with missing rights. Here’s the command that returns this error:
Invoke-RestMethod -Credential $NSCreds -Method PUT -Uri “http://HOST/nitro/v1/config/sslvserver/$vipname” -ContentType “application/json” -Body $DHDisableBody

Anyone knows what might be causing this? Is it necessary to provide credentials inside the body maybe? I tried everything and nothing works.


Typically, REST APIs need some kind of authentication token, which (to my limited knowledge) is typically passed as an entry within the header values.

Thanks Joel,
DELETE and GET operations didn’t require that, so I suppose PUT doesn’t either. I could give it a try tomorrow…

Anyone else has some other suggestions?

That would be my guess as well. The only way to know would be to consult the docs for the API, though. It’s not a PowerShell thing; you’re just not passing something it wants.

PUT, as a higher permission than GET (think: Write/Modify v.s. Read-Only) most likely requires the auth token more than a GET request would.

Thank you for your help. Turned out I had to switch from basic to oauth authentication.
I had to run “http://$netscalerIP/nitro/v1/config/login” first to get the websession. Now all the other queries instead of using -credential use -WebSession $loginsession parameter and it’s all happy.