Shutdown Proxmox using APi

Surgical

New Member
Jul 21, 2021
4
0
1
27
Hi Guys

So long story short I want to shut down my physical server that is running Proxmox VE using the API. I am fairly new to using API but what I have found thus far is this:
curl https://yourip:8006/api2/json//nodes/proxmox/stop -k -d 'username=root@pam&password=yourpassword'

Above does not seem to work, Anyone able to assist and just provide the correct curl to use

Thanx
 

Dunuin

Famous Member
Jun 30, 2020
9,000
2,313
156
Germany
Please don't use the root user for that. It is possible to create a new user, name it "shutdown" or something like that, create a new role like "shutdown", add the "shutdown" role to the "shutdown" user. If you then only give that role the rights to use "Sys.PowerMgmt" that user is only allowed to start/shutdown/reboot the node.
Never a good idea to use the root user and its password in clear text. The password could end up in logs if the command fails to execute and so on.
 
Last edited:

Surgical

New Member
Jul 21, 2021
4
0
1
27
Please don't use the root user for that. It is possible to create a new user, name it "shutdown" or something like that, create a new role like "shutdown", add the "shutdown" role to the "shutdown" user. If you then only give that role the rights to use "Sys.PowerMgmt" that user is only allowed to start/shutdown/reboot the node.
Never a good idea to use the root user and its password in clear text. The password could end up in logs if the command fails to execute and so on.
Noted thanx man. But do you know what Command I should use? Above post did not work
 

Dunuin

Famous Member
Jun 30, 2020
9,000
2,313
156
Germany
You could try it with this:
Code:
curl 'https://REPLACEMEWITHIPORHOSTNAME:8006/api2/extjs/nodes/NODENAME/status' -H 'Cookie: PVEAuthCookie=REPLACEMEWITHCORRECTCOOKIE' -H 'Content-Type: application/x-www-form-urlencoded' -H 'CSRFPreventionToken: REPLACEMEWITHCORRECTTOKEN' --data 'command=shutdown' --insecure
And by using tokens you don't got the problem with the passwords.
 
Last edited:

Surgical

New Member
Jul 21, 2021
4
0
1
27
Hey Man. No it did not seem to work. I don't know where to find the cookie. So to give more context I want to run this command from a terminal in Home Assistant as I'm using automation to turn my device off before scheduled power outages in my area. And I need to get this to work before I can Migrate all my VM's over from VMWARE Workstation to Proxmox lol
 

Glowsome

Active Member
Jul 25, 2017
152
24
43
50
The Netherlands
www.comsolve.nl
just my 5 cents, but ..

If a scheduelled power-outage were there, would a scheduelled cronjob on the Proxmox host be equally efficient, without poking around with the API ?

- if the scheduelled outage is always the same, then use a cronjob to shutdown the hosts/guests prior to the outage happens.
- if the outage is scheduelled on different times you can use the at daemon to schedule it ( this has my preference cause the job gets cleared after execution, meaning per occurane you will have to reschedule it.

or am i understanding the case as presented wrongly ?
 
Last edited:
  • Like
Reactions: gentoomaniac

Surgical

New Member
Jul 21, 2021
4
0
1
27
just my 5 cents, but ..

If a scheduelled power-outage were there, would a scheduelled cronjob on the Proxmox host be equally efficient, without poking around with the API ?

- if the scheduelled outage is always the same, then use a cronjob to shutdown the hosts/guests prior to the outage happens.
- if the outage is scheduelled on different times you can use the at daemon to schedule it ( this has my preference cause the job gets cleared after execution, meaning per occurane you will have to reschedule it.

or am i understanding the case as presented wrongly ?
This would work yes, but the times are not set. Sometimes weeks go by before power outages would occur. I live in South Africa so we get Load shedding (Then Power load is too high we receive 2 hours load shedding where we do not have power for 2 hours) now I have a system in place to run automation based on this. So far it turns off my server that is running Windows Server 2019, But if I move over to proxmox I need to also be able to do the same
 

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 your own in 60 seconds.

Buy now!