Hey everyone! I'm trying to connect to the Proxmox API using PowerShell, even though there's a dedicated module available. My goal here is to test some specific basic requests and see the raw outputs.
When I execute my script, I'm hit with an error saying the authorization header's format is invalid. My guess is that the characters `@` or `!` in my token ID might be causing the issue, but I can't pinpoint the exact fix.
Here's a snippet of my script:
```powershell
# Variables
$proxmoxHost = "https://10.0.0.1:8006"
$tokenID = 'steve@pam!im-steve'
$secret = 'im-a-random-string-of-characters'
# Auth header
$headers = @{
"Authorization" = "PVEAPIToken=" + "$tokenID=" + "$secret"
}
# Example: list nodes
$response = Invoke-WebRequest -Uri "$proxmoxHost/api2/json/nodes/proxy/9002/status/current" `
-Method Get `
-Headers $headers `
-UseBasicParsing
```
This gives me the error:
```
Invoke-WebRequest: The format of value 'PVEAPIToken=steve@pam!im-steve=im-a-random-string-of-characters' is invalid.
```
I've tried similar commands through `curl`, which works perfectly.
I would truly appreciate any insights or suggestions! Thanks!
4 Answers
Just to check, if you set the `Authorization` header without the `PVEAPIToken=` part (like so: `"$tokenID=$secret"`), does that make a difference? Sometimes, certain APIs are picky about formatting.
I noticed the way you concatenate your authorization string might be the issue. Try making your header like this:
```powershell
$headers = @{
"Authorization" = "PVEAPIToken=$tokenID=$secret"
}
```
Just remove the extra `+` and see if that solves the issue. Also, make sure there are no trailing spaces.
Another angle to consider is how your tokens are formatted. Given that you mentioned `curl` works but PowerShell doesn't, perhaps your escaping characters or overall string might need some tweaking. Maybe testing it with simpler tokens first could help.
Also, to eliminate any potential syntax issues, make sure the token and secret don’t have spaces or hidden characters that might be sneaking in.
Have you thought about adding the `-SkipHeaderValidation` flag to your `Invoke-WebRequest` command? This might help ignore any formatting issues with the headers. Just give it a shot and see if it clears things up!
Thanks for the quick suggestion! I tried it out, but I'm still hitting the same error.