0% found this document useful (0 votes)
105 views17 pages

VestaCP API

The document provides PHP code samples for interacting with the Vesta Control Panel API to automate tasks like creating user accounts, domains, databases and more. Code samples are given to create objects, list objects, delete objects, and check login credentials. The API returns numeric error codes that are documented.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views17 pages

VestaCP API

The document provides PHP code samples for interacting with the Vesta Control Panel API to automate tasks like creating user accounts, domains, databases and more. Code samples are given to create objects, list objects, delete objects, and check login credentials. The API returns numeric error codes that are documented.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

(/)

(https://github.com/serghey-rodin/vesta) (https://www.facebook.com/vestacp)

(https://twitter.com/vestacp)

LATEST VERSION (Jan 22): 0.9.8-26

Features Install Pricing Demo Docs Forum Sponsors


(/features/) (/install/) (/pricing/) (https://demo.vestacp.com)
(/docs/) (https://forum.vestacp.com)
(/sponsors/)

Vesta WEB API is available to perform core functions of the Control


Panel. We use it internaly to synchronyze DNS clusters, to integrate
WHMC billing system and to reset mail account passwords in
Roundcube. The API can be used as well to create new user
accounts, domains, databases or even to build an alternative web
interface.

This reference provides php code samples demonstrating how you


can seamlessly integrate API into your application or script. However
you can use other languages to commmunicate with API.

Create User Account


Create Web/DNS/Mail Domain All Together
Create Database
List User Account
List Web Domains
Delete User Account
Check Username and Password
Return Codes
Full Command List
<?php

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

// New Account
$username = 'demo';
$password = 'd3m0p4ssw0rd';
$email = '[email protected]';
$package = 'default';
$fist_name = 'Rust';
$last_name = 'Cohle';

// Prepare POST query


$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $password,
'arg3' => $email,
'arg4' => $package,
'arg5' => $fist_name,
'arg6' => $last_name
);
$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 "User account has been successfuly created\n";
} else {
echo "Query returned error code: " .$answer. "\n";
}
?>
<?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";
}
?>
<?php
// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_returncode = 'yes';
$vst_command = 'v-add-database';

// New Database
$username = 'demo';
$db_name = 'wordpress';
$db_user = 'wordpress';
$db_pass = 'wpbl0gp4s';

// 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);

// 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";
}
?>
<?php
// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_command = 'v-list-user';

// Account
$username = 'demo';
$format = 'json';

// Prepare POST query


$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $format
);
$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);

// Parse JSON output


$data = json_decode($answer, true);

// Print result
print_r($data);

?>
<?php
// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_command = 'v-list-web-domain';

// Account
$username = 'demo';
$domain = 'demo.vestacp.com';
$format = 'json';

// Prepare POST query


$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $domain,
'arg3' => $format
);
$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);

// Parse JSON output


$data = json_decode($answer, true);

// Print result
print_r($data);
?>
<?php
// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_returncode = 'yes';
$vst_command = 'v-delete-user';

// Account
$username = 'demo';

// Prepare POST query


$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username
);
$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 "User account has been successfuly deleted\n";
} else {
echo "Query returned error code: " .$answer. "\n";
}
?>
<?php
// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_command = 'v-check-user-password';
$vst_returncode = 'yes';

// Account
$username = 'demo';
$password = 'demopassword';

// Prepare POST query


$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $password
);
$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 "OK: User can login\n";
} else {
echo "Error: Username or password is incorrect\n";
}
?>

VALUE NAME COMMENT

0 OK Command has been successfuly performed

1 E_ARGS Not enough arguments provided

2 E_INVALID Object or argument is not valid

3 E_NOTEXIST Object doesn't exist

4 E_EXISTS Object already exists

5 E_SUSPENDED Object is suspended

6 E_UNSUSPENDED Object is already unsuspended

7 E_INUSE Object can't be deleted because is used by the other object

8 E_LIMIT Object cannot be created because of hosting package limits

9 E_PASSWORD Wrong password

10 E_FORBIDEN Object cannot be accessed be the user

11 E_DISABLED Subsystem is disabled

12 E_PARSING Configuration is broken

13 E_DISK Not enough disk space to complete the action

14 E_LA Server is to busy to complete the action

15 E_CONNECT Connection failed. Host is unreachable

16 E_FTP FTP server is not responding

17 E_DB Database server is not responding

18 E_RRD RRDtool failed to update the database

19 E_UPDATE Update operation failed

20 E_RESTART Service restart failed


Features (/features/) LICENCING:

History (/history/) GNU GENERAL PUBLIC LICENCE Version 3


Install (/install/)
The GNU General Public Licence is a free, copyleft licence for software
Pricing (/pricing/) and other kinds of works. Its free to change, modify and redistribute
source code.
Documentation (/docs/)
Demo (https://demo.vestacp.com)
Forum (https://forum.vestacp.com)
SOURCE CODES ARE AVAILABLE: FOR HOSTERS:
Sponsors (/sponsors/)

http://github.com We have special offer for hosting


companies, just contact us to start
(https://github.com/serghey- cooperation.
rodin/vesta)

Copyright © 2024 Vesta Control Panel. All right reserved. facebook CONTACT US:
[email protected]
(https://www.facebook.com
(mailto:[email protected])
/vestacp/)
twitter
(https://twitter.com/vestacp/)

You might also like