Proxmox 8 API agent/exec changes

BelCloud

Renowned Member
Dec 15, 2015
96
5
73
www.belcloud.net
Hello

I have noticed that in Proxmox 8, the <command> parameter for the API call POST /api2/json/nodes/{node}/qemu/{vmid}/agent/exec has been changed from <string> to <array> in the format: [string, ...]

Does anyone have a working example with the new format?

I have tried to send it as array, but the format doesn't seem to be recognized by the API:
PHP:
array(2) {
  ["data"]=>
  NULL
  ["errors"]=>
  array(3) {
    ["command[0]"]=>
    string(85) "property is not defined in schema and the schema does not allow additional properties"
    ["command[1]"]=>
    string(85) "property is not defined in schema and the schema does not allow additional properties"
    ["command"]=>
    string(42) "property is missing and it is not optional"
  }
}

On the old format "command arg1 arg2", I'm just receiving null.

Thank you
 
Last edited:
Can you provide an actual example of your usage of the API?

Based on the API Viewer [0] it should just be a list containing the command, followed by the arguments: ['cmd', 'arg1', 'arg2', ...]
I've used `pvesh` to test it, but passing `--comand` with an array argument worked.


[0] https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/agent/exec
 
  • Like
Reactions: BelCloud
Do you have the actual call somewhere available in JSON format?
That could help narrow down where the issue lies. Sadly I don't have experience with PHP.
 
  • Like
Reactions: BelCloud
Thank you for the reply!

With curl, it should be something like this:

Bash:
curl -sSk -H 'Authorization: PVEAPIToken=TOKEN' -X POST --data command[]="/bin/bash"  --data command[]="/tmp/myscript" https://HOST:8006/api2/json/nodes/NODE/qemu/100/agent/exec

But it returns the same error as with my php library.
I assume that the command needs to be in another format. Does it work only as json?
 
If I understand that correctly, you're sending multiple arrays.
But the command should be a single array containing multiple strings: ['cmd', 'arg1', 'arg2']
In JSON this would be something like "command": ["cmd", "arg1", "arg2"]
 
In theory, it's a single array called command, that's how it's normally done when sending a POST with urlencode data.
The exact JSON counterpart of the above request is {"command":["\/bin\/bash","\/tmp\/myscript"]} , but sending it as JSON will require modifying all existing Proxmox libraries from urlencode to json.
 
It looks like -d 'command=/bin/bash&command=/tmp/myscript' would work, and -d 'command=/bin/bash' -d 'command=/tmp/myscript'
 
Last edited:
Thank you very much!

Do you know if there are any other planned changes to this function, as parameters? As it's a breaking change from 7 to 8 and the new implementation will create a lot of issues in existing libraries.


It might be better to deprecate the command parameter and create a new one with the array.
 

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!