Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section Scripting / API
  • Search

API Bugs add new domain

Questions regarding the API
Application Programming Interface
Locked
  • Print view
Advanced search
5 posts • Page 1 of 1
www.rinku31
Posts: 21
Joined: Thu Jun 04, 2015 9:22 am

API Bugs add new domain

Post by www.rinku31 » Wed Mar 09, 2016 10:08 am

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 :)
Top

tjebbeke
Collaborator
Posts: 783
Joined: Mon May 11, 2015 8:43 am
Contact:
Contact tjebbeke
Website

Os: CentOS 6x
Web: apache + nginx
Re: API Bugs add new domain

Post by tjebbeke » Thu Mar 10, 2016 5:25 pm

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).
Top

www.rinku31
Posts: 21
Joined: Thu Jun 04, 2015 9:22 am

Re: API Bugs add new domain

Post by www.rinku31 » Thu Mar 17, 2016 6:02 am

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.
Top

wwwork
Posts: 1
Joined: Tue Mar 22, 2016 12:06 pm

Re: API Bugs add new domain

Post by wwwork » Tue Mar 22, 2016 12:28 pm

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

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: API Bugs add new domain

Post by skurudo » Fri Sep 23, 2016 12:37 pm

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
Top


Locked
  • Print view

5 posts • Page 1 of 1

Return to “Scripting / API”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password