Deepak1
February 17, 2025, 7:30am
1
I am unable to get the database details by using curl_call using the api_key
Here is my code…
$hst_hostname = ‘hestiacp.nuftp.com ’;
$hst_port = ‘8083’;
$hst_returncode = ‘no’;
$hst_username = ‘admin’;
$hst_command = ‘v-list-databases’;
$hst_apikey = ‘80WMzpsdsYduWfgdfdfdfdf_oXNw_Qx’;
How I can fetch the database details using curl_call api_key
eris
February 17, 2025, 8:14am
2
What is your return code?
Legacy api enabled?
Deepak1
February 17, 2025, 8:30am
3
In the curl response, i am getting the panel login page.
below is the curl response…
Welcome to Hestia Control Panel
Username
Next
How I can enable legacy API…?
eris
February 17, 2025, 8:49am
4
You try to access https://hostname.com:8083
Full api url you need to provide is
https://hostname.com:8083/api/
See example below:
<?php
// Server credentials
$hst_hostname = 'server.hestiacp.com';
$hst_port = '8083';
$hst_apikey = ‘80WMzpsdsYduWfgdfdfdfdf_oXNw_Qx’;
$hst_returncode = 'no';
$hst_command = 'v-list-databases';
// Prepare POST query
$postvars = array(
'hash' => $hst_apikey,
'returncode' => $hst_returncode,
'cmd' => $hst_command,
'arg1' => $username,
;
// 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);
// Check result
if($answer === 0) {
echo "Database has been successfuly created\n";
} else {
echo "Query returned error code: " .$answer. "\n";
}
Deepak1
February 17, 2025, 9:11am
5
It looks like i am not passing the correct key(‘hash’) for api_key in $postvars hence not getting the response…now my issue is resolved.
Can you include this information on hestiacp guide/documentation?
eris
February 17, 2025, 9:13am
6
But is quite limited.
Some more examples can be found:
Examples for Hestia API
And of course the CLI list with all the commands
Deepak1
February 17, 2025, 9:24am
7
I am using curl like this…is that correct
$param array(‘action’=>‘listdbs’, ‘key’=>‘my_api_key_goes_here’);
$url = ‘https://hestiacp.nuftp.com:8083/myplugin/index.php?act=cp_api&api=serialize ’;
$strCookie = ‘HESTIASID=’ . $_COOKIE[‘HESTIASID’] . ‘; path=/’;
//r_print($_COOKIE);
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq = http_build_query($params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// UserAgent
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
//curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=' . $_COOKIE['PHPSESSID']);
curl_setopt($ch, CURLOPT_COOKIE, $strCookie);
session_write_close();
// Get response from the server.
$chunk = curl_exec($ch);
echo 'curl_call'.$chunk.'curlend';
echo 'curl_error:'.curl_error($ch);
curl_close ($ch);
file_put_contents(‘/tmp/chunk.txt’, var_export($chunk,1));
Deepak1
February 17, 2025, 9:25am
8
one more thing i missed
$strCookie = ‘HESTIASID=’ . $_COOKIE[‘HESTIASID’] . ‘; path=/’;
eris
February 17, 2025, 10:29am
10
You trying to connect to something else then the API?
Deepak1
February 17, 2025, 10:35am
11
i am trying to fetch the database list of the user using the api_key and cookie_id in my curl but in the curl response it is return login page.
It looks like your control panel is clone of the vestacp.
The same curl is working fine on vestacp.
eris
February 17, 2025, 10:43am
12
You don’t need to autencatie with COOKIE so on…
Use hostname.domain.com:8083/api/
And use the example I have provided in the example.
Deepak1
February 17, 2025, 10:50am
13
Thanks for help and provide proper guidance on this topic.
Again thank you so much.