Api does not work

Hello I try to receive in json format the list of all domains but it does not work, I only receive a 0

<?php // Server credentials $hst_hostname = 'hostname'; $hst_port = '8083'; $hst_returncode = 'no'; $hst_username = 'admin'; $hst_password = '123456'; $hst_returncode = 'yes'; $hst_command = 'v-list-web-domains'; // Account $username = 'demo'; $format = 'json'; // Prepare POST query $postvars = array( 'user' => $hst_username, 'password' => $hst_password, 'returncode' => $hst_returncode, 'cmd' => $hst_command, 'arg1' => $username, 'arg2' => $format, ); // Send POST query via cURL $postdata = http_build_query($postvars); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); $answer = curl_exec($curl); // Parse JSON output $data = json_decode($answer, true); // Print result print_r($data); it seems that the last lines of php code from hestia / web / api / index.php leads nowhere if (isset($_POST['user']) || isset($_POST['hash'])) { api($_POST['hash'], $_POST['user'], $_POST['password'], $_POST['returncode'], $_POST['cmd'], $_POST['arg1'], $_POST['arg2'], $_POST['arg3'], $_POST['arg4'], $_POST['arg5'], $_POST['arg6'], $_POST['arg7'], $_POST['arg8'], $_POST['arg9']);| } else if (json_decode(file_get_contents("php://input"), true) != NULL){ //JSON POST support| $json_data = json_decode(file_get_contents("php://input"), true); api($json_data['hash'], $json_data['user'], $json_data['password'], $json_data['returncode'], $json_data['cmd'], $json_data['arg1'], $json_data['arg2'], $json_data['arg3'], $json_data['arg4'], $json_data['arg5'], $json_data['arg6'], $json_data['arg7'], $json_data['arg8'], $json_data['arg9']);| } else { echo "Error: data received is null or invalid, check https://docs.hestiacp.com/admin_docs/api.html"; exit; } the answer is always 0 if I run the command v-list-web-domains demo json from shell it works but inside php it doesn't`Preformatted text`

Please reformat your post, it isnt really readable.

Hello I try to receive in json format the list of all domains but it does not work, I only receive a 0

$hst_hostname = ‘hotname’;
$hst_port = ‘8083’;
$hst_returncode = ‘no’;
$hst_username = ‘admin’;
$hst_password = ‘1253456’;
$hst_returncode = ‘yes’;
$hst_command = ‘v-list-web-domains’;

$username = ‘demo’;
$format = ‘json’;

$postvars = array(
‘user’ => $hst_username,
‘password’ => $hst_password,
‘returncode’ => $hst_returncode,
‘cmd’ => $hst_command,
‘arg1’ => $username,
‘arg2’ => $format,
);

// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ‘https://’ . $hst_hostname . ‘:’ . $hst_port . ‘/api/’);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);

// Parse JSON output
$data = json_decode($answer, true);

// Print result
print_r($data);

it seems that the last lines of php code from hestia / web / api / index.php leads nowhere

if (isset($_POST[‘user’]) || isset($_POST[‘hash’])) {

api($_POST[‘hash’], $_POST[‘user’], $_POST[‘password’], $_POST[‘returncode’], $_POST[‘cmd’], $_POST[‘arg1’], $_POST[‘arg2’], $_POST[‘arg3’], $_POST[‘arg4’], $_POST[‘arg5’], $_POST[‘arg6’], $_POST[‘arg7’], $_POST[‘arg8’], $_POST[‘arg9’]);|

} else if (json_decode(file_get_contents(“php://input”), true) != NULL){ //JSON POST support|
$json_data = json_decode(file_get_contents(“php://input”), true);
api($json_data[‘hash’], $json_data[‘user’], $json_data[‘password’], $json_data[‘returncode’], $json_data[‘cmd’], $json_data[‘arg1’], $json_data[‘arg2’], $json_data[‘arg3’], $json_data[‘arg4’], $json_data[‘arg5’], $json_data[‘arg6’], $json_data[‘arg7’], $json_data[‘arg8’], $json_data[‘arg9’]);

} else {
echo “Error: data received is null or invalid, check Rest Api — Hestia Control Panel documentation”;
exit;
}

the answer is always 0 if I run the command v-list-web-domains demo json from shell it works but inside php it doesn’t` worck

sorry the first time when I write there was no way to put it on line

Should be “no”

If yes it will indeed return an error code “0”

sorry I had it in no but copy the code of the example

does not work in any way does not return any json data

Anyone knows how to solve this?

Example as I told should work fine…

But here is a test script allowing easy testing

thanks for answering

I’m a php programmer and I know how to do
$ answer = curl_exec ($ curl);
echo $ answer;

or

$answer = curl_exec($curl);

// Parse JSON output
$data = json_decode($answer, true);

// Print result
print_r($data);

and it doesn’t work I always get a 0 nothing else
I did this today in vestacp which is similar and works perfectly but in hestiacp it does not work

what if I see that the codes of /web/api/index.php of vestacp is a little different from web / api / index.php of hestiacp but I do not see what is the fault that does not collect the output json and print_r in php in json format and only shows a 0

If I create a user with v-add-user it works correct even though the answer is 0 but then when I want to list the users the answer is 0

If returncode == yes then echo de code is 0 if not it should display OK or a json list

Last time I tried it it did work fine and since then no changes has been made…

i found the problem in the above parameters I have 2 lines of code

$hst_returncode = ‘no’;
$hst_returncode = ‘yes’;

first I say no then I say yes i the result is 0

removed the yes it works properly thanks for the help

where I find a list of all api commands?
all commands from cli core scripts serve as api commands?

https://docs.hestiacp.com/cli_commands.html

Might be out of date…