[SOLVED] API calls to Proxmox BS

BabboDemonio

New Member
Dec 5, 2022
3
0
1
Hi!
I wrote a small bash script in order to shutdown a Proxmox VE remotely by using an API call. The invocation is this one:
Bash:
curl -X POST -H "Authorization: PVEAPIToken=root@pam!TOKEN=TOKEN_VALUE" -H "Content-Type: application/x-www-form-urlencoded" -d "command=shutdown" https://proxmoxve.DOMAIN.COM/api2/json/nodes/pve/status

This works and I am happy with it.

Now I am trying to do the same thing for a Proxmox Backup server. I created a token and the first thing that I noticed is that there is a mismatch between the docs and what I find in the UI. According to the docs there should be a path like nodes/{node}/status, while on the UI I only see this
1671734983728.png
Assuming that the right permission path is /system/status, I created a token and I am trying to use it like I did for Proxmox VE, for example:
Bash:
curl -X POST -H "Authorization: PVEAPIToken=root@pam!TOKEN=TOKEN_VALUE" -H "Content-Type: application/x-www-form-urlencoded" -d "command=shutdown" https://proxmoxbs.DOMAIN.COM/api2/json/nodes/pbs/status

but I keep getting authentication failed - no authentication credentials provided.. I am pretty sure the path is correct because if I manually open the respective path while logged in a browser I can see the correct response.

So am I missing something? Is the invocation to Proxmox Backup server different than the one for Proxmox VE?
Thanks
 
Hi,

I guess the Authorization should PBSAPIToken not PVEAPIToken, since it's a PBS not a PVE ;) i.e:

Bash:
curl -X POST -H "Authorization: PBSAPIToken=root@pam!TOKEN=TOKEN_VALUE" -H "Content-Type: application/x-www-form-urlencoded" -d "command=shutdown" https://proxmoxbs.DOMAIN.COM/api2/json/nodes/pbs/status
 
what @Moayad said w.r.t. the token prefix is correct

to shed some light on the other confusion - when talking about the API you have to be careful not to mix up the two different kind of paths:
- API endpoint path (like /nodes/{node}/status), this tells the API server which code handles your request
- ACL path (like /datastore/foobar (where foobar is a datastore identifier), or /system/status), this encodes what your API token is allowed to access

e.g., in the api viewer when browsing to /nodes/{node}/status, you will see the following under "Required permissions":
Code:
Check: {"partial":false,"path":["system","status"],"privs":["Sys.Audit"]}

this means you need the "Sys.Audit" privilege on the (ACL!) path "/system/status" to access the API endpoint "/nodes/{node}/status"
 
Hi!,
thanks to both of you for you explanation! I tried to change the command like @Moayad suggested but I got this:

authentication failed - invalid token name

After reasearching a bit I found another post that seems to suggest that for PBS the separator needs to be : not =. I tried this and all worked fine:

Bash:
curl -X POST -H "Authorization: PBSAPIToken=root@pam!TOKEN:TOKEN_VALUE" -H "Content-Type: application/x-www-form-urlencoded" -d "command=shutdown" https://proxmoxbs.DOMAIN.COM/api2/json/nodes/pbs/status

I think it would be useful to post these instructions somewhere because I couldn't find them easily and I had to ask here in the forum :). Something like what was done for Proxmox VE
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!