Error connecting to api
Error connecting to api
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.
$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.
-
- Support team
- Posts: 1111
- Joined: Tue Jul 30, 2013 10:18 pm
- Contact:
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: Error connecting to api
API working for admin user only.
https://github.com/serghey-rodin/vesta/ ... dex.php#L8
https://github.com/serghey-rodin/vesta/ ... dex.php#L8