Page 1 of 1

Error 4 adding (unexisting) domain with v-add-domain

Posted: Fri Aug 25, 2017 1:48 pm
by willowmagrini
Hello,
I´m trying to create a domain with PHP following this guide: https://vestacp.com/docs/api/#add_domain .
In my website I ´ve created a form to fill the data and send it to the script above.

I´m getting "Query returned error code: 4" even when the domain doesn't exists.
Vesta is creating Web/DNS/Mail but returning Error.
Anybody had that yet?
thanks

My function:

Code: Select all

function cria_web($user,$endereco){
 $vst_hostname = 'xxxxxxxx';
 $vst_username = 'xxxxxxxx';
 $vst_password = 'xxxxxxxx;
 $vst_returncode = 'yes';
 $vst_command = 'v-add-domain';

 // New Domain
 // Prepare POST query
 $postvars = array(
     'user' => $vst_username,
     'password' => $vst_password,
     'returncode' => $vst_returncode,
     'cmd' => $vst_command,
     'arg1' => $user,
     'arg2' => $endereco
 );
 $postdata = http_build_query($postvars);

 // Send POST query via cURL
 $postdata = http_build_query($postvars);
 $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 "Domain has been successfuly created\n";
 }
 else {
     echo "Query returned error code: " .$answer. "\n";
 }
}