Help with Proxmox API Authorization Error in PowerShell

0
4
Asked By TechieTurtle42 On

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

Answered By DebugDude On

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.

Answered By CodingNinja99 On

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.

TechieTurtle42 -

Thanks for the quick suggestion! I tried it out, but I'm still hitting the same error.

Answered By _POWERShellGuru_ On

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.

Answered By SyntaxSorcerer On

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!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.