https://github.com/webfoersterei/hetzner-cloud-api-client
API Client for managing Hetzner's Cloud
https://github.com/webfoersterei/hetzner-cloud-api-client
api-client hetzner hetzner-cloud
Last synced: 11 months ago
JSON representation
API Client for managing Hetzner's Cloud
- Host: GitHub
- URL: https://github.com/webfoersterei/hetzner-cloud-api-client
- Owner: webfoersterei
- License: mit
- Created: 2018-01-23T15:36:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-27T17:45:27.000Z (about 7 years ago)
- Last Synced: 2025-08-09T02:47:19.653Z (11 months ago)
- Topics: api-client, hetzner, hetzner-cloud
- Language: PHP
- Size: 36.1 KB
- Stars: 7
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hetzner-cloud-api-client
API Client for managing Hetzner's Cloud
[](https://travis-ci.org/webfoersterei/hetzner-cloud-api-client)
[](https://packagist.org/packages/webfoersterei/hetzner-cloud-api-client)
[](https://packagist.org/packages/webfoersterei/hetzner-cloud-api-client)
[](https://github.com/webfoersterei/hetzner-cloud-api-client/blob/master/LICENSE)
## Usage
Install this package via composer ``composer require webfoersterei/hetzner-cloud-api-client "dev-master@dev"``
**Note:** There is no stable release at the moment
After that you can use the client like this:
```php
define('API_KEY', 'MYSECRETAPIKEY'); # See https://docs.hetzner.cloud/#header-authentication-1
$cloudApiClient = Webfoersterei\HetznerCloudApiClient\ClientFactory::create(API_KEY);
# You can now use the cloudApiClient. E.g:
$cloudApiClient->getServers();
```
## Implemented Methods
The client provides implementations for the following methods (grouped by resources).
### Actions
See: https://docs.hetzner.cloud/#resources-actions
* List all: `getActions()`
* Get one: `getAction(int $id)`
### Servers
See: https://docs.hetzner.cloud/#resources-servers
* Get all: `getServers()`
* Get one: `getServer(int $id)`
* Create one: `createServer(CreateRequest $createRequest)`
* Rename: `changeServerName(int $id, string $name)`
* Delete one: `deleteServer(int $id)`
### ServerTypes
See: https://docs.hetzner.cloud/#resources-server-types
* Get all: `getServerTypes()`
* Get one: `getServerType(int $id)`
### Pricing
See: https://docs.hetzner.cloud/#resources-pricing-get
* Get all: `getPricing()`
## Contribute
Feel free to contribute to this github repository by reporting bugs and ideas to improve this API-client.
## Examples
### List of serverTypes
Lists all serverTypes: name and specs
```php
# Require vendors/autoload.php here
define('API_KEY', 'MYSECRETAPIKEY');
$client = \Webfoersterei\HetznerCloudApiClient\ClientFactory::create(API_KEY);
$serverTypes = $client->getServerTypes();
foreach ($serverTypes->server_types as $serverType) {
printf("%--12s CPU: %2d Cores, RAM: %3d GB, Storage: %4d GB (%s)\n", $serverType->name, $serverType->cores,
$serverType->memory, $serverType->disk, $serverType->storage_type);
}
```
### My first server
Create a new server and delete it after started
```php
# Require vendors/autoload.php here
define('API_KEY', 'MYSECRETAPIKEY');
$client = \Webfoersterei\HetznerCloudApiClient\ClientFactory::create(API_KEY);
$createServerRequest = new \Webfoersterei\HetznerCloudApiClient\Model\Server\CreateRequest();
$createServerRequest->name = 'my-first-server-created-with-php';
$createServerRequest->server_type = 'cx11';
$createServerRequest->start_after_create = true;
$createServerRequest->image = 1;
echo "Creating server.\n";
$createResponse = $client->createServer($createServerRequest);
$progress = $createResponse->action->progress;
$status = $createResponse->action->status;
while ($progress != 100 && $status != 'success') {
$actionResponse = $client->getAction($createResponse->action->id);
echo $actionResponse->action->progress."%\n";
$progress = $actionResponse->action->progress;
sleep(1);
}
echo sprintf("Server created. Root-PW: %s\n", $createResponse->root_password);
sleep(10);
echo "Deleting server.\n";
$client->deleteServer($createResponse->server->id);
echo "Done.\n";
```