Invoke-RestMethod and "Not Logged In" error

This topic contains 5 replies, has 3 voices, and was last updated by  Kamil G 1 week ago.

  • Author
    Posts
  • #98547

    Kamil G
    Participant

    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

    Joel Sallow
    Participant

    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

      Kamil G
      Participant

      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

      Joel Sallow
      Participant

      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

    Don Jones
    Keymaster

    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

    Kamil G
    Participant

    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.

You must be logged in to reply to this topic.