Client API Documentation

api.png

We offer "VPS API" which enables you to perform basic functions even outside control panel. The API requires authentication. You can generate API key and API Access Hash by clicking "GENERATE" under "Manage VPS --> VPS SETTINGS --> API".

api.png

Step 1 - Manage API keys

In the future if you would like to you can also:

  1. Disable API keys by pressing "Disable". disable-api.png
  2. Enable API keys by pressing "Enable". enable-api.png
  3. Regenerate API keys and hash all together by pressing "Generate".

Step 2 - Functions

Once you generate the API, you can use the following functions:

2.1 Reboot virtual server

Function .............. : Reboot virtual server
Action ................ : reboot
Method ................ : GET or POST
Returned values ....... : \success\ and \rebooted\

2.2 Boot virtual server

Function .............. : Boot virtual server
Action ................ : boot
Method ................ : GET or POST
Returned values ....... : \success\ and \booted\

2.3 Shutdown virtual server

Function .............. : Shutdown virtual server
Action ................ : shutdown
Method ................ : GET or POST
Returned values ....... : \success\ and \shutdown\

2.4 Virtual server status

Function .............. : Get virtual server status
Action ................ : status
Method ................ : GET or POST
Returned values ....... : \success\ and \online|offline\

2.5 Virtual server information

Function .............. : Get virtual server information. Setting any flag to true will return the result.
Action ................ : info
Method ................ : GET or POST
Flags ................. : 
- ipaddr (Returns a list of ipaddresses)
- hdd (Returns the hard disk usage in Bytes)
- mem (Returns the memory usage in Bytes)
- bw (Returns the bandwidth usage in Bytes)
Returned values ....... : 
\123.123.123.123,122.122.122.122,111.111.111.111\
\total,used,free,percentused\
\total,used,free,percentused\
\total,used,free,percentused\

2.6 Extras

The following is returned on a success status:

\[hostname]\
\[mainipaddress]\

You can specify the status to be returned on any of the queries by adding status=true to the query. The returned data will contain:

\online|offline\

3. PHP Code Examples

<?php

// Url to the API.
$url = "https://vps.simpliservers.com/api/client";

// Specify the key, hash and action.
$postfields["key"] = "EXAMPLE-API-KEY";
$postfields["hash"] = "EXAMPLE-HASH";
$postfields["action"] = "reboot"; // reboot, shutdown, boot, status

// Send the query to the panel.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . "/command.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

// Parse the returned data and build an array.
preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $match);
$result = [];
foreach ($match[1] as $x => $y) {
    $result[$y] = $match[2][$x];
}
?>

// Output all returned data
<?php print_r($result); ?>

// Parsing returned data
<?php
// Check for any errors
if ($result["status"] == "error") {
    echo $result["statusmsg"];
    exit();
}

// Display a message on a successful return.
if ($result["status"] == "success") {
    if ($result["statusmsg"] == "online") {
        echo "The virtual server is online!";
    } elseif ($result["statusmsg"] == "offline") {
        echo "The virtual server is offline!";
    } elseif ($result["statusmsg"] == "rebooted") {
        echo "The virtual server has been rebooted!";
    } elseif ($result["statusmsg"] == "shutdown") {
        echo "The virtual server has been shutdown!";
    } elseif ($result["statusmsg"] == "booted") {
        echo "The virtual server has been booted!";
    } else {
        echo "Status message unknown!";
    }
}
?>