API call response null

alve89

New Member
Apr 9, 2024
12
0
1
Hi all,

following the guide at https://pve.proxmox.com/wiki/Proxmox_VE_API#Ticket_Cookie I just tried to start my LXC container:

1. Call:
Bash:
curl -k -d 'username=api@pve' --data-urlencode "password@/Volumes/Daten/pw.pve" https://pve.lan:8006/api2/json/access/ticket
2: Response:
JSON:
{"data":{"username":"api@pve","cap":{"access":{"User.Modify":1,"Group.Allocate":1},"dc":{"SDN.Use":1,"SDN.Audit":1,"SDN.Allocate":1,"Sys.Audit":1},"storage":{"Datastore.Allocate":1,"Datastore.AllocateTemplate":1,"Datastore.Audit":1,"Datastore.AllocateSpace":1},"nodes":{"Sys.Syslog":1,"Sys.Console":1,"Sys.Audit":1},"sdn":{"SDN.Audit":1,"SDN.Allocate":1,"SDN.Use":1},"vms":{"VM.Monitor":1,"VM.Allocate":1,"VM.Backup":1,"VM.Console":1,"VM.Config.Disk":1,"VM.Config.Memory":1,"VM.Config.CDROM":1,"VM.Snapshot":1,"VM.Config.Network":1,"VM.Config.Options":1,"VM.Clone":1,"VM.Config.Cloudinit":1,"VM.PowerMgmt":1,"VM.Snapshot.Rollback":1,"VM.Config.CPU":1,"VM.Audit":1,"VM.Config.HWType":1,"VM.Migrate":1},"mapping":{"Mapping.Audit":1,"Mapping.Use":1}},"CSRFPreventionToken":"66348398:tFqMoSo153cyKT8nDVJdK7hvMBJWR49O1CKxYw1V82s","ticket":"PVE:api@pve:66348....KXDA=="}}%
3. Call with new ticket:
Bash:
curl -k -b "PVEAuthCookie=PVE:api@pve:66348....KXDA==" https://pve.lan:8006/api2/json/nodes/pve/lxc/109/status/start
4: Response:
JSON:
{"data":null}%

What am I doing wrong?

My goal is to only start and stop the container by the API. I'd like to try it with API keys as the next step, but first the basics should work...


PS: This works:
Bash:
pvesh create /nodes/pve/lxc/109/status/start
also
Bash:
curl -k -b "PVEAuthCookie=PVE:api@pve:66348....KXDA==" https://pve.lan:8006/api2/json/nodes/pve/lxc/109/status/current
JSON:
{"data":{"cpu":0,"diskwrite":0,"diskread":0,"maxdisk":34359738368,"status":"stopped","netin":0,"type":"lxc","ha":{"managed":0},"maxswap":536870912,"uptime":0,"netout":0,"cpus":4,"name":"cctv","mem":0,"swap":0,"maxmem":4294967296,"vmid":109,"disk":0}}%
 
Last edited:
I just tried with -v :
Code:
*   Trying 192.168.20.186:8006...
* Connected to pve.lan (192.168.20.186) port 8006
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* ALPN: server did not agree on a protocol. Uses default.
* using HTTP/1.x
> GET /api2/json/nodes/pve/lxc/109/status/start HTTP/1.1
> Host: pve.lan:8006
> User-Agent: curl/8.4.0
> Accept: */*
> Cookie: PVEAuthCookie=PVE:api@pve:66348....KXDA==
>
< HTTP/1.1 501 Method 'GET /nodes/pve/lxc/109/status/start' not implemented
< Cache-Control: max-age=0
< Connection: close
< Date: Fri, 03 May 2024 09:09:31 GMT
< Pragma: no-cache
< Server: pve-api-daemon/3.0
< Content-Length: 13
< Content-Type: application/json;charset=UTF-8
< Expires: Fri, 03 May 2024 09:09:31 GMT
<
{"data":null}* Closing connection
* schannel: shutting down SSL/TLS connection with pve.lan port 8006

So it seems you're right with
the endpoint to start a VM expects a POST request, not a GET.

I saw your linked site but I didn't notice the POST requirement there...


For all with the same question, this is the solution:

Bash:
curl -k -b "PVEAuthCookie=PVE:api@pve:66348....KXDA==" -X POST -H "CSRFPreventionToken: 66348.....c9gVU" https://pve.lan:8006/api2/json/nodes/pve/lxc/109/status/start

Thank you for clarification @Folke!