How I can fetch the database details using curl_call api_key

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

What is your return code?

Legacy api enabled?

In the curl response, i am getting the panel login page.
below is the curl response…

Hestia Control Panel

Welcome to Hestia Control Panel

Username
Next

How I can enable legacy API…?

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

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?

But is quite limited.

Some more examples can be found:

And of course the CLI list with all the commands

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

one more thing i missed
$strCookie = ‘HESTIASID=’ . $_COOKIE[‘HESTIASID’] . ‘; path=/’;

any update on this

You trying to connect to something else then the API?

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.

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.

Thanks for help and provide proper guidance on this topic.
Again thank you so much.