Invoke-RestMethod and "Not Logged In" error

Welcome Forums General PowerShell Q&A Invoke-RestMethod and "Not Logged In" error

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
6 months, 1 week ago.

  • Author
    Posts
  • #98547

    Participant
    Points: 0
    Rank: Member

    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.

    Thanks
    K

  • #98550

    Participant
    Points: 2
    Rank: Member

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

    • #98553

      Participant
      Points: 0
      Rank: Member

      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?

    • #98565

      Participant
      Points: 2
      Rank: Member

      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.

  • #98562

    Keymaster
    Points: 1
    Rank: Member

    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.

  • #98622

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘Invoke-RestMethod and "Not Logged In" error’ is closed to new replies.