Page 1 of 1

API Bugs add new domain

Posted: Wed Mar 09, 2016 10:08 am
by www.rinku31
Let me explain :

i have put vesta admin login details in vestacon.php and it is connecting fine.

I create a user rinkunn ok
And exampledo.com domain is not present.

I run this code:

Code: Select all

<?php
require("vestacon.php");
$vst_returncode = 'yes';
$vst_command = 'v-add-domain';

// New Domain
$username = "rinkunn";
$domain = "exampledo.com";

// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'returncode' => $vst_returncode,
    'cmd' => $vst_command,
    'arg1' => $username,
    'arg2' => $domain
);
$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";
}


Output:

Query returned error code: 4 ( i was expecting Domain has been successfuly created )

But this code has added this domain .

ok i reload this web page again:

Output:
Query returned error code: 4


So funny API :)

Re: API Bugs add new domain

Posted: Thu Mar 10, 2016 5:25 pm
by tjebbeke
Try the same thing in the control panel. I think the domain you try to create already exists (error code 4: E_EXISTS - Object already exists).

Re: API Bugs add new domain

Posted: Thu Mar 17, 2016 6:02 am
by www.rinku31
This code adding new domain but return wrong response. response it same in both case, in first case, it add domain successfully but return error response. and officially second response is error and it is right because domain is already present.

Re: API Bugs add new domain

Posted: Tue Mar 22, 2016 12:28 pm
by wwwork
I've run "v-add-domain" code from API help and recieved error code 2 - E_INVALID (Object or argument is not valid) and domain has not been added.

But when I've create POST query in the browser plugin - it was created successfuly.

Where is the bug?

Code: Select all

<?php

// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_returncode = 'yes';
$vst_command = 'v-add-domain';

// New Domain
$username = 'demo';
$domain = 'demo.vestacp.com';

// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'returncode' => $vst_returncode,
    'cmd' => $vst_command,
    'arg1' => $username,
    'arg2' => $domain
);
$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";
}
?>

Re: API Bugs add new domain

Posted: Fri Sep 23, 2016 12:37 pm
by skurudo
API documentation and examples:
http://vestacp.com/docs/API.pdf

CLI commands list and descriptions:
http://vestacp.com/docs/CLI.txt

-> viewtopic.php?f=18&t=12610