Skip to content

webdock-io/php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-sdk

CI

PHP SDK Library / Wrapper for the Webdock API

Installation

Composer

To use the Webdock SDK, install it to your project with Composer.

  • composer require webdock/php-sdk

Example Usage

<?php
require_once 'vendor/autoload.php';
$appName = 'YourAppName/v1.0';
$token = 'Your access token';
$client = new \Webdock\Client($token, $appName);


# Create a new server instance
$params = [
  'name' => 'mynewserver1',
  'slug' => 'mynewserver1',
  'locationId' => 'fi',
  'profileSlug' => 'webdockmicro',
  'imageSlug' => 'krellide:webdock-focal-lemp-php74',
];

$newServer = $client->server->create($params);

# To view HTTP Header Response
var_dump($newServer->getHeaders()->toArray());

# To view API call stats
var_dump($newServer->getApiStats());

# To view server response object
var_dump($newServer->getResponse());

# To view Server response in Array
var_dump($newServer->getResponse()->toArray());

# To view callbackID (if the endpoint is in asynchronous task. i.e. deleting server)
var_dump($newServer->getCallbackID());

?>

Documentation

Full API documentation is available at https://api.webdock.io/

API References

  • GET /ping Sends a ping request to the Webdock API

    Show example
    $ping = $client->ping();
    
    var_dump($ping->getResponse()->toArray());
  • GET /account/accountInformation Get Account Information

    Show example
    $accountInfo = $client->accountInformation->get();
  • GET /servers Get a list of your servers

    Show example
    $status = 'active'; // [all, suspended, active]
    $serverList = $client->server->list($status);
    
    # to view the result
    foreach ($serverList->getResponse() as $server) {
      echo $server->name;
    }
    
    # or cast the response as arrays
    var_dump($serverList->getResponse()->toArray());
    
    # each individual item can be casted as an array too
    foreach ($serverList->getResponse() as $server) {
      var_dump($server->toArray());
    }
  • POST /servers Create a server

    Show example
    $params = [
      'name' => 'mynewserver1',
      'slug' => 'mynewserver1',
      'locationId' => 'fi', # get available locations: $client->location->list();
      'profileSlug' => 'webdockmicro',
      'imageSlug' => 'krellide:webdock-focal-lemp-php74',
    ]
    $newServer = $client->server->create($params);
  • GET /servers/{serverSlug} Get a specific server by slug

    Show example
    $slug = 'your-server-slug';
    $server = $client->server->get($slug);
    
    # Since the result is a single element, compared to the previous example (GET /servers), the response is in object/stdclass style
    
    echo $server->getResponse()->name;
    
    # We can also cast the response as an array
    var_dump($server->getResponse()->toArray());
  • DELETE /servers/{serverSlug} Delete a server

    This endpoint requires special privileges, if you want to enable this endpoint please contact Webdock support!

    Show example
    $slug = 'your-server-slug';
    $deleteServer = $client->delete($slug);
  • PATCH /servers/{serverSlug} Update server metadata

    Show example
    $slug = 'mynewserver1';
    $params = [
      'nextActionDate' => '2020-10-10',
      'name' => 'new server name',
      'description' => 'new server description',
      'notes' => 'another notes',
    ];
    $updateServer = $client->server->update($slug, $params);
  • POST /servers/{serverSlug}/actions/start Start a server

    Show example
    $slug = 'mynewserver1';
    $startServer = $client->serverAction->start($slug);
  • POST /servers/{serverSlug}/actions/stop Stop a server

    Show example
    $slug = 'mynewserver1';
    $stopServer = $client->serverAction->stop($slug);
  • POST /servers/{serverSlug}/actions/reboot Reboot a server

    Show example
    $slug = 'mynewserver1';
    $stopServer = $client->serverAction->reboot($slug);
  • POST /servers/{serverSlug}/actions/suspend Suspend a server

    Show example
    $slug = 'mynewserver1';
    $stopServer = $client->serverAction->suspend($slug);
  • POST /servers/{serverSlug}/actions/reinstall Reinstall a server

    Show example
    $slug = 'mynewserver1';
    $image = 'krellide:webdock-focal-lemp-php74';
    $stopServer = $client->serverAction->reinstall($slug, $image);
  • POST /servers/{serverSlug}/actions/snapshot Create a snapshot for a server

    Show example
    $slug = 'mynewserver1';
    $snapshotName = 'my server snapshot';
    $stopServer = $client->serverAction->snapshot($slug, $snapshotName);
  • POST /servers/{serverSlug}/actions/restore Restore the server to a snapshot

    Show example
    $slug = 'mynewserver1';
    $snapshotId = 1203;
    $stopServer = $client->serverAction->restore($slug, $snapshotId);
  • POST /servers/{serverSlug}/actions/resize/dryrun Dry Run for Server Profile Change

    Show example
    $slug = 'mynewserver1';
    $profileSlug = 'server-profile-a'; # Get the server profile in $client->profile->list($locationId);
    $stopServer = $client->serverAction->dryRunResize($slug, $profileSlug);
  • POST /servers/{serverSlug}/actions/resize Change a Server Profile

    Show example
    $slug = 'mynewserver1';
    $profileSlug = 'server-profile-a';
    $stopServer = $client->serverAction->resize($slug, $profileSlug);
  • GET /locations Get a list of possible server datacenter locations

    Show example
    $locations = $client->location->list();
  • GET /profiles Get a list of possible server hardware profiles

    Show example
    $locationId = 1002;
    $locations = $client->profile->list($locationId);
  • GET /images Get a list of possible server software images

    Show example
    $images = $client->image->list();
  • GET /account/publicKeys Get a list of public keys in your Webdock account

    Show example
    $myPublicKeys = $client->publicKey->list();
  • POST /account/publicKeys Add a new public key

    Show example
    $params = [
      'name' => 'my laptop public key',
      'publicKey' => 'ssh-rsa AAAB3...',
    ];
    $addPublicKey = $client->publicKey->create($params);
  • DELETE /account/publicKeys/{id} Delete a PublicKey

    Show example
    $publicKeyId = 12021;
    $deletePublicKey = $client->publicKey->delete($publicKeyId);
  • GET /servers/{serverSlug}/shellUsers Get a list of shell users for a server

    Show example
    $serverSlug = 'mynewserver1';
    $shellUsers = $client->serverShellUser->list($serverSlug);
  • POST /servers/{serverSlug}/shellUsers Create a shell user in a server

    Show example
    $serverSlug = 'mynewserver1';
    $params = [
      'username' => 'user1',
      'password' => 'X1xq0e-12k',
      'group' => 'user1',
      'shell' => 'zsh',
      'publicKeys' => [12021],
    ];
    $createShellUser = $client->serverShellUser->create($serverSlug, $params);
  • DELETE /servers/{serverSlug}/shellUsers/{shellUserId} Deletes a shell user

    Show example
    $serverSlug = 'mynewserver1';
    $shellUserId = 40591;
    
    $deleteShellUser = $client->serverShellUser->delete(
      $serverSlug,
      $shellUserId
    );
  • PATCH /servers/{serverSlug}/shellUsers/{shellUserId} Update shell user Public Keys in a server

    Show example
    $serverSlug = 'mynewserver1';
    $shellUserId = 40591;
    $params = ['publicKeys' => [1293, 19283]];
    $updateShellUser = $client->serverShellUser->update(
      $serverSlug,
      $shellUserId,
      $params
    );
  • GET /account/scripts Get a list of account scripts

    Show example
    $accountScripts = $client->accountScript->list();
  • POST /account/scripts Create an account script

    Show example
    $params = [
      'name' => 'my account script',
      'filename' => 'filename',
      'content' => 'the content',
    ];
    $createAccountScript = $client->accountScript->create($params);
  • GET /account/scripts/{scriptId} Get an account script by ID

    Show example
    $scriptId = 1203;
    $accountScript = $client->accountScript->get($scriptId);
  • DELETE /account/scripts/{scriptId} Delete an account script

    Show example
    $scriptId = 1203;
    $deleteAccountScript = $client->accountScript->delete($scriptId);
  • PATCH /account/scripts/{scriptId} /account/scripts/{scriptId}

    Show example
    $scriptId = 1203;
    $params = [
      'name' => 'updated script#1',
      'filename' => 'myscript.sh',
      'content' => 'thecontent',
    ];
    $updateAccountScript = $client->accountScript->update($scriptId, $params);
  • GET /scripts Get a list of public scripts

    Show example
    $scripts = $client->script->list();
  • GET /servers/{serverSlug}/scripts Get a list of server scripts

    Show example
    $serverSlug = 'mynewserver1';
    $scripts = $client->serverScript->list($serverSlug);
  • POST /servers/{serverSlug}/scripts Create a server script

    Show example
    $serverSlug = 'mynewserver1';
    $params = [
      'scriptId' => 123,
      'path' => '/path/to/script',
      'makeScriptExecutable' => true,
      'executeImmediately' => true,
    ];
    $createServerScript = $client->serverScript->create($serverSlug, $params);
  • GET /servers/{serverSlug}/scripts/{scriptId} Get a server script by ID

    Show example
    $serverSlug = 'mynewserver1';
    $scriptId = 123;
    $script = $client->serverScript->get($serverSlug, $scriptId);
  • DELETE /servers/{serverSlug}/scripts/{scriptId} Delete a server script

    Show example
    $serverSlug = 'mynewserver1';
    $scriptId = 123;
    $deleteScript = $client->serverScript->delete($serverSlug, $scriptId);
  • POST /servers/{serverSlug}/scripts/{scriptId}/execute Execute a server script

    Show example
    $serverSlug = 'mynewserver1';
    $scriptId = 123;
    $executeScript = $client->serverScript->executeScript($serverSlug, $scriptId);
    $callbackId = $executeScript->getCallbackID();
  • POST /servers/{serverSlug}/fetchFile Fetches a file from the server

    Show example
    $serverSlug = 'mynewserver1';
    $filePath = '/path/to/file';
    $fetchFile = $client->serverScript->fetchFile($serverSlug, $filePath);
  • GET /servers/{serverSlug}/metrics Get server metrics

    Show example
    $serverSlug = 'mynewserver1';
    $metric = $client->serverMetric->getMetrics($serverSlug);
  • GET ​/servers​/{serverSlug}​/metrics​/now Get instant metrics

    Show example
    $serverSlug = 'mynewserver1';
    $metric = $client->serverMetric->getMetricsNow($serverSlug);
  • GET /servers/{serverSlug}/snapshots Get a list of snapshots for a server

    Show example
    $serverSlug = 'mynewserver1';
    $snapshots = $client->serverSnapshot->list($serverSlug);
  • GET ​/servers​/{serverSlug}​/snapshots​/{snapshotId} Get a snapshot by ID for a server

    Show example
    $serverSlug = 'mynewserver1';
    $snapshotId = 1022;
    $snapshot = $client->serverSnapshot->get($serverSlug, $snapshotId);
  • DELETE /servers/{serverSlug}/snapshots/{snapshotId} Deletes a snapshot by ID for a server

    Show example
    $serverSlug = 'mynewserver1';
    $snapshotId = 1022;
    $deleteSnapshot = $client->serverSnapshot->delete($serverSlug, $snapshotId);
  • GET /hooks Get a list of event hooks

    Show example
    $eventHooks = $client->eventHook->list();
  • POST /hooks Creates an event hook

    Show example
    $params = [
      'callbackUrl' => 'the_callback_url',
      'callbackId' => 10293,
    ];
    $createEventHook = $client->eventHook->create($params);
  • GET /hooks/{hookId} Get an event hook by ID

    Show example
    $hookId = 1223;
    $eventHook = $client->eventHook->get($hookId);
  • DELETE /hooks/{hookId} Deletes an event hook

    Show example
    $hookId = 1223;
    $deleteEventHook = $client->eventHook->delete($hookId);
  • GET /events Get a list of events

    Show example
    $params = [];
    $events = $client->eventPoll->list($params);

About

PHP SDK Library / Wrapper for the Webdock API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages