Proxmox 8 API exec not working

Peppe2201

Active Member
Aug 28, 2018
14
2
43
23
Hello everyone,
we use the API in Proxmox quite extensively, especially the agent -> exec function to execute commands in VMs.
After upgrading from Proxmox 7 to Proxmox 8, this specific function no longer works properly, we get specifically:

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"
}
}

As per the documentation we noticed that strings are no longer accepted but arrays, but even reformatting the request, we get "null" as the response.
Here an example of a request payload working in PVE 7: [ "command": "touch test" ]

Could you please help us figure out how to modify the requests to work in PVE 8?
 
Hello everyone,
we use the API in Proxmox quite extensively, especially the agent -> exec function to execute commands in VMs.
After upgrading from Proxmox 7 to Proxmox 8, this specific function no longer works properly, we get specifically:

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"
}
}

As per the documentation we noticed that strings are no longer accepted but arrays, but even reformatting the request, we get "null" as the response.
Here an example of a request payload working in PVE 7: [ "command": "touch test" ]

Could you please help us figure out how to modify the requests to work in PVE 8?
Hi,
you will have to pass the command + arguments as array. What client are you using to access the API? Something like e.g {"command": ["touch", "test"]} should work.
 
Hi,
we're using a PHP library just for wrapped auth to PVE, then we're trying to send to the node, in PVE 8, the commands with this pattern: {"command": ["touch", "test"]} but we receive:
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"
}
}
 
Hi,
we're using a PHP library just for wrapped auth to PVE, then we're trying to send to the node, in PVE 8, the commands with this pattern: {"command": ["touch", "test"]} but we receive:
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"
}
}
please share part of the code and/or the payload, maybe we can spot the error. From the output it seems that you are missing the property command, which might indicate that you payload is not formatted as expected. Does your wrapper code encode the payload to valid json?
 
No, the library does not modify the parameters but simply passes them as form_params in a post.

The library in question is the following: https://github.com/JWaldecker/ProxmoxVE, here it takes care of taking over the request via the create() -> https://github.com/JWaldecker/Proxm...029a255a900cfdba082ac920/src/Proxmox.php#L359, here the function to handle the configs passed to the create: https://github.com/JWaldecker/Proxm...029a255a900cfdba082ac920/src/Proxmox.php#L129

Here the script that is run:
$config = ['command' => [ 'touch', 'test' ], 'input-data' => ''];
$proxmox = new Proxmox($cluster, 'array', new Client([
'timeout' => 30,
'connect_timeout' => 30,
'read_timeout' => 30,
]));

$data = $proxmox->create("/nodes/{$vm->node}/qemu/{$vmid}/agent/exec", $config);
print($data);

Resulting in the error output I shared with you above.
 
I was able to reproduce your issue, unfortunately the problem seems to be in how the GuzzleHttp client prepares your payload. Instead of sending the expected {"command": ["cmd", "arg"]}, the payload is split into {"command[0]": "cmd", "command[1]": "arg"}, explaining also the error message.

The easiest workaround is to patch this Proxmox PHP client you are using by passing json encoded payload. This can be done by adding the Content-Type: application/json header and pass the payload as 'body' => json_encode($params), instead of 'form_params' => $params,. After patching the client, the API call worked for me with the following code:
PHP:
<?php
require_once 'vendor/autoload.php';

use ProxmoxVE\Proxmox;

$credentials = [
    'hostname' => '<your-hostname>',
    'username' => '<your-username>',
    'password' => '<your-password>',
];

$proxmox = new Proxmox($credentials);
$payload = ['command' => ['ls', '-la']];
$data = $proxmox->create("/nodes/<your-node>/qemu/<your-vm-id>/agent/exec", $payload);
print_r($data);

If needed, I can provide a patch.
 
Last edited:
Hi Chris,
thanks a lot! Do you think that this'll be a path compatible with PVE 7?
We're using this tool for PVE 7 clusters
 
Hi Chris,
thanks a lot! Do you think that this'll be a path compatible with PVE 7?
We're using this tool for PVE 7 clusters
Hmm, not exactly sure if I understand your question, the patch I am talking about would be a hotfix for the PHP client, not PVE. If you are asking of the patched client should be able to communicate with a PVE7 installation then yes, this should work also for PVE 7, as what changes is the formatting of the payload.

Best would be to open an issue at https://github.com/JWaldecker/ProxmoxVE so the can have a deeper look and fix it for all users.
 
Hi Chris,
thanks a lot! Can you provide us the patch, we'll fork the repo and try to make a pull req
 
Hi Chris,
thanks a lot! Can you provide us the patch, we'll fork the repo and try to make a pull req
Here you go
Code:
From 65b9079da00c442e8ba81524a50127b62b44cddb Mon Sep 17 00:00:00 2001
From: Christian Ebner <c.ebner@proxmox.com>
Date: Mon, 23 Oct 2023 08:54:16 +0200
Subject: [PATCH] http client: json encode api call payloads

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 src/Proxmox.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Proxmox.php b/src/Proxmox.php
index 6096e3d..c2ea5ae 100644
--- a/src/Proxmox.php
+++ b/src/Proxmox.php
@@ -131,7 +131,7 @@ class Proxmox
                     'http_errors' => false,
                     'cookies' => $cookies,
                     'headers' => $headers,
-                    'form_params' => $params,
+                    'json' => $params,
                 ]);
             default:
                 $errorMessage = "HTTP Request method {$method} not allowed.";
--
2.39.2

This is basically all I needed for the php api client to work here, see also https://docs.guzzlephp.org/en/stable/request-options.html#json
 
Hi guys,
here our fork with the patch: https://github.com/Uania-srl/ProxmoxVE

Thanks a lot for your help!

PS:
We had to make other changes to limit the addition of the json parameter to the exec endpoint and POST calls only, because inserting that flag would stop all other POST (stop/start/reboot) and all DELETE (remove HA, remove VM) calls from working.
 
  • Like
Reactions: Chris
Hi guys,
here our fork with the patch: https://github.com/Uania-srl/ProxmoxVE

Thanks a lot for your help!

PS:
We had to make other changes to limit the addition of the json parameter to the exec endpoint and POST calls only, because inserting that flag would stop all other POST (stop/start/reboot) and all DELETE (remove HA, remove VM) calls from working.
Thanks for sharing!
 

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!