Question regarding API

Hello,

I’m trying to get a list of domains per user, outputted in a php page.

I’m playing around with the example pages found in the hestia documentation zone, i assume it’s working, because if i set returncode to yes, i get a 0 (command succesfull)

If i change returncode to no, no output comes on screen. There must be something i’m missing, maybe someone can help me to find the good way:

<?php

// Server credentials
$hst_hostname = 'yyy';
$hst_port = 'yyy';
$hst_returncode = 'no';
$hst_username = 'yyy';
$hst_password = 'yyy';
$hst_command = 'v-list-web-domains';

// Account
$username = 'aaa';

// Prepare POST query
$postvars = array(
    'user' => $hst_username,
    'password' => $hst_password,
    'returncode' => $hst_returncode,
    'cmd' => $hst_command,
    'arg1' => $username,
);
$postdata = http_build_query($postvars);

// 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);
?>

OK, here we go…

I have changed this:

// 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);
?>

To this:

// 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);
?>
<pre>
<?php
$answer = curl_exec($curl);

// Print result
print_r($answer);
?>
</pre>

The JSON decode didn’t return anything, but if i print the answer directly, i have my output.
Next step, trying to find out how i can build this up with CSS to have a nice layout.

To be continued… (I think :slight_smile: )

‘arg2’ => ‘json’,

Will return as json format

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.