PHP code example of cedricziel / php-hetzner-cloud-api

1. Go to this page and download the library: Download cedricziel/php-hetzner-cloud-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/ */

    

cedricziel / php-hetzner-cloud-api example snippets


$token = '...';

// create an api client
$client = new \CedricZiel\HetznerCloudAPI\Client();

// set the credentials on your client
$client->authenticate($token);

// retrieve a list of servers
$client->servers->all();

// retrieve all actions
$actions = $client->actions->all();

// get one action
$action = $client->actions->show($actionId);

// retrieve all images
$images = $client->images->all();

// get one image
$image = $client->images->show($imageId);

// retrieve all prices
$prices = $client->pricing->all();

// retrieve all servers
$server = $client->servers->all();

// get one server
$server = $client->servers->show($serverId);

// create a server
$server = $client->servers->create($parameters);

// rename a server
$server = $client->servers->rename($serverId, $newName);

// remove a server
$client->servers->remove($serverId);

// retrieve all server actions
$actions = $client->server_actions->all();

// get one server action
$action = $client->server_actions->show($actionId);

// powerOn
$action = $client->server_actions->powerOn($serverId);

// reboot
$action = $client->server_actions->reboot($serverId);

// reset
$action = $client->server_actions->reset($serverId);

// powerOn
$action = $client->server_actions->powerOn($serverId);

// shutdown
$action = $client->server_actions->shutdown($serverId);

// powerOff
$action = $client->server_actions->powerOff($serverId);

// resetPassword
$action = $client->server_actions->resetPassword($serverId);

// enableRescueMode
$action = $client->server_actions->enableRescueMode($serverId);

// disableRescueMode
$action = $client->server_actions->disableRescueMode($serverId);

// createImage
$action = $client->server_actions->createImage($serverId, $parameters);

// rebuild
$action = $client->server_actions->rebuild($serverId, $parameters);

// changeType
$action = $client->server_actions->changeType($serverId, $parameters);

// enableBackup
$action = $client->server_actions->enableBackup($serverId, $parameters);

// disableBackup
$action = $client->server_actions->disableBackup($serverId);

// attachIso
$action = $client->server_actions->attachIso($serverId, $parameters);

// detachIso
$action = $client->server_actions->detachIso($serverId);

// changeDnsPtr
$action = $client->server_actions->changeDnsPtr($serverId, $parameters);

// changeProtection
$action = $client->server_actions->detachIso($serverId, $parameters);

// requestConsole
$action = $client->server_actions->requestConsole($serverId);

// retrieve all SSH Keys
$keys = $client->ssh_keys->all();

// get one SSH Key
$key = $client->ssh_keys->show($keyId);

// create a SSH Key
$key = $client->ssh_keys->create($parameters);

// rename a SSH Key
$key = $client->ssh_keys->rename($keyId, $name);

// remove a SSH Key
$key = $client->ssh_keys->remove($keyId);