1. Go to this page and download the library: Download praxisnetau/serverpilot-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
praxisnetau / serverpilot-api example snippets
use ServerPilot\ServerPilotAPI;
$api = ServerPilotAPI::inst('<client-id>', '<api-key>');
$api->servers; // For server commands
$api->sysusers; // For system user commands
$api->apps; // For app commands
$api->dbs; // For database commands
$api->actions; // For action status commands
if ($server = $api->servers->get('<server-id>')) {
$server->setFirewall(true);
$server->setAutoUpdates(true);
$server->update(); // <-- server is updated via the API
}
if ($app = $api->apps->get('<app-id>')) {
$app->setRuntime('php7.1');
$app->addDomain('myapp.mydomain.com');
$app->removeDomain('myapp.anotherdomain.com');
$app->update(); // <-- app is updated via the API
}
if ($app = $api->apps->get('<app-id>')) {
$app->delete(); // <-- app has been deleted via the API, be careful!
}
if ($action = $api->getLastAction()) {
$id = $action->getID(); // ID of the action
$data = $action->getData(); // data returned by the API for the action
$object = $action->getObject(); // data model object created for the action
}
$id = $api->getLastActionID(); // ID of the last action
if ($action = $api->getLastAction()) {
if ($status = $action->getStatus()) {
$id = $status->getID(); // ID of the action status
$status = $status->getStatus(); // status text ('open', 'error', or 'success')
$serverId = $status->getServerID(); // ID of the server
$dateCreated = $status->getDateCreated(); // timestamp of the status
if ($status->isOpen()) {
// The action hasn't finished yet!
}
if ($status->isError()) {
// Whoops, something went wrong!
}
if ($status->isSuccessful()) {
// Huzzah, it worked!
}
}
}
$status = $api->getLastActionStatus(); // returns an ActionStatus object for last action