Error - Invalid Operation - Powershell Vault Token Generation using Approle

when i try to generate a token for the vault using powershell in my script to be then able to insert / update secret into vault i get the below error during the token generation using the role id and secret id.

PS C:\windows\system32> $ClientToken = Invoke-WebRequest -Method POST -Uri “$VaultAddress/auth/approle/login” -Body $Payload
Invoke-WebRequest : {“errors”:}
At line:1 char:16

  • … ientToken = Invoke-WebRequest -Method POST -Uri "$VaultAddress/auth/a …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

You might be missing the /v1/ path segment from this URL, but you haven’t provided the contents of $VaultAddress, so I can’t be sure.

PowerShell is awful about providing clear feedback about REST errors, in my experience. My suggestion would be to use any other language if you can.

Hi - Issue was resolved after I used postman to send a vault token request and took the powershell code from it, looks like i was missing the header application/json and the json payload was not having the proper escape character for double quotes.