Page 1 of 1

Error connecting to api

Posted: Fri Jun 19, 2020 9:04 pm
by martincr
Hello, I am working on a script that works with vesta to create a database, take the example of the vesta page script, when I send the data by curl it returns a false boolean and the database registration is not done . This is my script :

$basedatos = $this->bd_clonada;
// Server credentials
$vst_hostname = 'digicloudmx.com';
$vst_username = 'digicloudmx';
$vst_password = 'mypass';
$vst_returncode = 'yes';
$vst_command = 'v-add-database';
$username = "prueba";

//$username = $basedatos;

$db_name = $basedatos;
$db_user = $this->bd_usuario;
$db_pass = $this->bd_password;

// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $db_name,
'arg3' => $db_user,
'arg4' => $db_pass
);

$postdata = http_build_query($postvars);
var_dump($postdata); die;
// Send POST query via cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/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";
}

What am I doing wrong? What do I need to activate on the server? or how I know that the hostname is correct starting there.

Re: Error connecting to api

Posted: Fri Jun 19, 2020 9:46 pm
by grayfolk