Search code examples
powershellhashicorp-vault

getting "missing client token" while accessing get API of hashicorp vault


I'm trying to get the secrets from a location in hashicorp vault busing below powershell script

$response = Invoke-RestMethod -Headers "X-Vault-Token: $($VaultAuthToken)" -Method Get -Uri "https://{Vault URL}/{Namespace}/v1/secret/{App Path}"

But I'm facing below error message

missing client token

Please suggest on this.


Solution

  • The -Headers parameter accepts a dictionary object with key-value pairs corresponding to the headers you want to add to the request, not bare strings.

    Change it to the following and it should work:

    $response = Invoke-RestMethod -Headers @{'X-Vault-Token' = $VaultAuthToken} -Method Get -Uri "https://{Vault URL}/{Namespace}/v1/secret/{App Path}"