Key points
- PHP code that drives the DigitalOcean and Vultr APIs: list your droplets and servers, then act on them by node ID.
- Both APIs have moved on: DigitalOcean switched off v1 and Vultr is on v2, both with a bearer token. A PHP 7.4 version for DigitalOcean’s v2 API is included.
- The original downloads are kept for reference.
My First Experience with a VPS API PHP Wrapper
Updated October 2026: The code in this 2014 post was written for versions of each VPS API that have changed:
- DigitalOcean switched off its v1 API (the one that used a client ID and API key) in 2015; the old v1 address now answers “Your request could not be routed”. Use API v2 with a personal access token, or the official
doctlcommand line tool. - Vultr’s current API is v2 at
https://api.vultr.com/v2, also with a Bearer token, so my Vultr wrapper needs the new endpoints. - The downloads below are kept for reference. Under the first method I added a short PHP version for DigitalOcean API v2 that lists droplets and reboots one, with the Vultr v2 equivalents in a comment. Each download now has a README that says so, and do-api.zip also carries that v2 version as
do-api-v2.php. - Stealth Walker, the panel shown in the screenshot, is now an archived project.
Here is my first experience with an API PHP wrapper. DigitalOcean and Vultr provide VPS services, so if you don’t want to log into their panel each time you want to perform an action on the VPS node, you can call the droplet functions from your own website and have your own control panel. In 2014 you needed your own client ID and API key, both generated from the DigitalOcean control panel; today you create a personal access token there instead (see the update above). Here is the code that I wrote to list all the droplets and perform actions like reboot, shutdown, and power on:
DigitalOcean first method
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Digital Ocean API Implementation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<table width="700px">
<tr>
<td colspan="6">Data Center Control</td>
</tr>
<tr>
<td style="text-align:center">Server ID</td>
<td style="text-align:center">Server Name</td>
<td style="text-align:center">IP</td>
<td style="text-align:center">Status</td>
<td style="text-align:center">Creation Date</td>
<td style="text-align:center">Actions</td>
</tr>
<?php
/* PHP script written by Warith AL Maawali
# (c) 2014 Warith AL Maawali
# https://www.digi77.com
# http://www.om77.net
# script starts here:*/
// Add your own client keys here
$myClientID="xxxxxxxxxxxx";
// Add your own API keys here
$myDOApi="xxxxxxxxxxxxxxxxxxxx";
// Get current time to speed
$loadingtime = time();
// Get your data from the API provider
$json = file_get_contents("https://api.digitalocean.com/v1/droplets/?client_id=$myClientID&api_key=$myDOApi");
$data = json_decode($json);
// Get live hosts
$liveCounter = substr_count($json, 'status":"active');
// Get Offline hosts
$deadCounter = substr_count($json, 'status":"off');
// Sum the total
$counterSum=$liveCounter + $deadCounter;
foreach($data -> droplets as $mydata)
{
// Set the droplet id for further actions
$serverid=$mydata->id;
?>
<tr>
<td style="text-align:center"><?php echo $mydata->id; ?></td>
<td style="text-align:center"><?php echo $mydata->name; ?></td>
<td style="text-align:center"><?php echo $mydata->ip_address; ?></td>
<td style="text-align:center"><?php echo $mydata->status; ?></td>
<td style="text-align:center"><?php echo $mydata->created_at; ?></td>
<td class="td_title4" style="text-align:center"><?php echo "<a href=\"https://api.digitalocean.com/droplets/$serverid/reboot/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"red\">Reboot</font></a> - <a href=\"https://api.digitalocean.com/droplets/$serverid/shutdown/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"red\">Shut Down</font></a> - <a href=\"https://api.digitalocean.com/droplets/$serverid/power_on/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"red\">Power On</font></a>" ?></td>
<?php
}//end for
?>
</tr>
<tr>
<td colspan="2">
Online Droplets: <?php echo "<font color=\"green\">" . $liveCounter . "</font>"?><br />
Offline Droplets: <?php echo "<font color=\"red\">" . $deadCounter . "</font>"?><br />
Total Droplets: <?php echo "<font color=\"black\">" . $counterSum . "</font>"?><br />
<?php echo "Query Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br />\n"; ?>
</td>
</tr>
</table>
</body>
</html>
DigitalOcean shut down the v1 API this code was written for; this PHP 7.4 or newer version calls API v2 with a personal access token:
<?php
// DigitalOcean API v2: a personal access token (Control Panel, API, Tokens) replaces the old client ID and API key
function doApi(string $method, string $path, ?array $body = null): array
{
$ch = curl_init('https://api.digitalocean.com/v2' . $path);
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('DIGITALOCEAN_TOKEN'),
'Content-Type: application/json',
],
];
if ($body !== null) {
$opts[CURLOPT_POSTFIELDS] = json_encode($body);
}
curl_setopt_array($ch, $opts);
$data = json_decode((string) curl_exec($ch), true);
return is_array($data) ? $data : [];
}
// List the droplets
foreach (doApi('GET', '/droplets?per_page=200')['droplets'] ?? [] as $d) {
echo $d['id'], ' ', $d['name'], ' ', $d['status'], "\n";
}
// Reboot one droplet (other action types: power_off, power_on, shutdown, power_cycle)
doApi('POST', '/droplets/123456789/actions', ['type' => 'reboot']);
// Vultr API v2 works the same way: base URL https://api.vultr.com/v2, the same Bearer header with your
// Vultr API key, GET /instances to list servers and POST /instances/{id}/reboot to reboot one.
DigitalOcean second method
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Digital Ocean API Implementation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<table width="700px">
<tr>
<td colspan="6">Data Center Control</td>
</tr>
<tr>
<td style="text-align:center">Server ID</td>
<td style="text-align:center">Server Name</td>
<td style="text-align:center">IP</td>
<td style="text-align:center">Status</td>
<td style="text-align:center">Creation Date</td>
<td style="text-align:center">Actions</td>
</tr>
<?php
/* PHP script written by Warith AL Maawali
# (c) 2014 Warith AL Maawali
# https://www.digi77.com
# http://www.om77.net
# script starts here:*/
//<!-- Api stuff starts here -->
//talk to digital ocean via API
require_once('DO.class.php');
$myClientID="Your_Own_Client_ID_From_Digitalocean"; // Add your own client keys here
$myDOApi="Your_Own_API_From_Digitalocean"; // Add your own API keys here
$ocean = new \DigitalOceanApi\DigitalOcean($myClientID,$myDOApi);
$droplets = get_object_vars($ocean->getDroplets());
$m=0;
foreach ($droplets as $drops)
{
if (is_array($drops))
{
//get number of droplets
$DropletArrayValues= serialize($droplets);
$NumberOfDroplets=substr_count($DropletArrayValues, 'image_id');
while($m<$NumberOfDroplets)
{
//get id of each droplet
$serverid=$drops[$m]->id;
?>
<tr>
<td style="text-align:center"><?php echo $drops[$m]->id; ?></td>
<td style="text-align:center"><?php echo $drops[$m]->name; ?></td>
<td style="text-align:center"><?php echo $drops[$m]->ip_address; ?></td>
<td style="text-align:center"><?php echo $drops[$m]->status; ?></td>
<td style="text-align:center"><?php echo $drops[$m]->created_at; ?></td>
<td class="td_title4" style="text-align:center"><?php echo "<a href=\"https://api.digitalocean.com/droplets/$serverid/reboot/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"#CCFB5D\">Reboot</font></a> - <a href=\"https://api.digitalocean.com/droplets/$serverid/shutdown/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"#CCFB5D\">Shut Down</font></a> - <a href=\"https://api.digitalocean.com/droplets/$serverid/power_on/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"#CCFB5D\">Power On</font></a>" ?></td>
<?php
$m++;
}//end while
}//end if
}//end for
//print all information for debug only
//print_r(array_values($droplets));
?>
</tr>
<tr>
<td colspan="2">
Total Droplets: <?php echo "<font color=\"red\">" . $NumberOfDroplets . "</font>"?><br />
</td>
</tr>
</table>
<!-- Api stuff ends here -->
</body>
</html>
You will need DO.class.php to be in the same folder as this script:
Download DO.class.php class from here.
Download do.php code from here.
A sample of the working code on the Stealth Walker admin control panel (now an archived project):
You can perform more actions as long as you have the node ID; the available actions can be found here.
Vultr method
My new experience is with the Vultr cloud VPS provider; you can see their API here. Now let me show you how to wrap it with PHP code. It is simple, with the same concept as above, except you won’t have an array.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Vultr API Implementation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<table width="700px">
<tr>
<td colspan="8">Data Center Control</td>
</tr>
<tr>
<td style="text-align:center">Server ID</td>
<td style="text-align:center">Server Name</td>
<td style="text-align:center">City</td>
<td style="text-align:center">IP</td>
<td style="text-align:center">Status</td>
<td style="text-align:center">Creation Date</td>
<td style="text-align:center">Bandwidth</td>
<td style="text-align:center">Backups</td>
</tr>
<?php
/* PHP script written by Warith AL Maawali
# (c) 2015 Warith AL Maawali
# https://www.digi77.com
# http://www.om77.net
# script starts here:*/
// Add your own API keys here
$myVultrApiKey="Get your own key from vultr.com";
// Get current time to speed
$loadingtime = time();
// Get your data from the API provider
$json = file_get_contents("https://api.vultr.com/v1/server/list?api_key=$myVultrApiKey");
$data = json_decode($json);
// Get live hosts
$liveCounter = substr_count($json, 'status":"active');
// Get Offline hosts
$deadCounter = substr_count($json, 'status":"off');
// Sum the total
$counterSum=$liveCounter + $deadCounter;
foreach ($data as $name => $value)
{
?>
<tr>
<td style="text-align:center"><?php echo $value->SUBID; ?></td>
<td style="text-align:center"><?php echo $value->label; ?></td>
<td style="text-align:center"><?php echo $value->location; ?></td>
<td style="text-align:center"><?php echo $value->main_ip; ?></td>
<td style="text-align:center"><?php echo $value->power_status; ?></td>
<td style="text-align:center"><?php echo $value->date_created; ?></td>
<td style="text-align:center"><?php echo $value->current_bandwidth_gb; ?></td>
<td style="text-align:center"><?php echo $value->auto_backups; ?></td>
<?php
}//end for
?>
</tr>
<tr>
<td colspan="2">
Online servers: <?php echo "<font color=\"green\">" . $liveCounter . "</font>"?><br />
Offline servers: <?php echo "<font color=\"red\">" . $deadCounter . "</font>"?><br />
Total servers: <?php echo "<font color=\"black\">" . $counterSum . "</font>"?><br />
<?php echo "Query Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br />\n"; ?>
</td>
</tr>
</table>
</body>
</html>
Download the Vultr API wrapper code from here.

