I will post an excerpt from my HA configuration.yaml which works with API for me:I know that this is a post for shuttting down the PVE host via the Rest API, but I tried adapting the solution of user @gfngfn256 to shutdown a VM on the node, following the Proxmox documentation I just had to make a few modifications. This was the result:Bash:'curl "https://$IP:$PORT/api2/extjs/nodes/{node}/stopall" -H "Authorization: PVEAPIToken=USER@REALM!TOKENID=UUID" -H "Content-Type: application/x-www-form-urlencoded" --data "vms=2201" --insecure'
But it returns the message: Permission check failed.
I have already verified that I'm using the correct Token and Token Secret by running the @gfngfn256 solution successfully and I also verified that VM.PowerMgmt Permission is correctly linked to the API Token.
I would appreciate any ideas on what the problem could be.
Thanks!
YAML:
shell_command:
start_lxc_<CTID>: 'curl -H "Authorization: PVEAPIToken=<UserName>!<TokenID>=<TokenSecret>" -X POST https://<IP>:8006/api2/json/nodes/<NodeName>/lxc/<CTID>/status/start --insecure'
stop_lxc_<CTID>: 'curl -H "Authorization: PVEAPIToken=<UserName>!<TokenID>=<TokenSecret>" -X POST https://<IP>:8006/api2/json/nodes/<NodeName>/lxc/<CTID>/status/stop --insecure'
start_vm_<VMID>: 'curl -H "Authorization: PVEAPIToken=<UserName>!<TokenID>=<TokenSecret>" -X POST https://<IP>:8006/api2/json/nodes/<NodeName>/qemu/<VMID>/status/start --insecure'
shutdown_vm_<VMID>: 'curl -H "Authorization: PVEAPIToken=<UserName>!<TokenID>=<TokenSecret>" -X POST https://<IP>:8006/api2/json/nodes/<NodeName>/qemu/<VMID>/status/shutdown --insecure'
Please note that I recently stopped using the API method to access Proxmox from within HA, and rather use SSH (by setting up a pair of SSH keys between HA and Proxmox).
My current configuration.yaml looks as follows:
YAML:
shell_command:
start_lxc_<CTID>: "ssh -i /config/id_rsa -o StrictHostKeyChecking=no root@<IP> -t 'pct start <CTID>'"
stop_lxc_<CTID>: "ssh -i /config/id_rsa -o StrictHostKeyChecking=no root@<IP> -t 'pct stop <CTID>'"
start_vm_<VMID>: "ssh -i /config/id_rsa -o StrictHostKeyChecking=no root@<IP> -t 'qm start <VMID>'"
shutdown_vm_<VMID>: "ssh -i /config/id_rsa -o StrictHostKeyChecking=no root@<IP> -t 'qm shutdown <VMID>'"
Its more robust & versatile. YMMV.
Remember which ever version you use, ALL THE QUOTES, DOUBLE-QUOTES, COMMAS ETC. MUST BE EXACTLY AS MINE TO WORK