Get the 1&1 PHP Cloud Server SDK

Table of Contents

Introduction

The 1&1 PHP SDK is a PHP library designed for interaction with the 1&1 Cloud platform over the Cloud Server REST API. This allows you to automate many of the tasks which are otherwise available through the Cloud Panel UI.

Features

The 1&1 PHP SDK allows you to list and retrieve information about servers, including their hardware, IP addresses, load balancers, private networks, and more. You can create and delete servers, as well as reconfigure them. Hard drives, virtual DVD units, firewall policies, load balancers, and IP addresses can all be added or removed through the API.

The API also allows you to manage server operations. Servers can be added to or removed from private networks. Snapshots can be created, restored, or removed. Images can be created, updated, and deleted. Shared storages, firewall policies, load balancers, IP addresses, private networks, VPNs, monitoring policies, logs, usage, and appliances can all be managed through the API. Users and roles can be added, deleted, and managed, as well.

Supported Versions

The 1&1 PHP SDK is designed for PHP version 7 and above.

Getting Started

Before you begin you will need to have signed-up for a 1&1 account. The credentials you setup during sign-up will be used to authenticate against the API.

Installation

You can install the latest stable version using Composer. If you don't already have Composer installed, follow their installation instructions here. Once you have Composer installed, add the snippet below to your composer.json file, and then run composer install (if you installed Composer globally), or php composer.phar install (if you installed locally) from your terminal. This will create a vendor directory in your repo, and now allows you to use the 1and1 PHP SDK.

{
    "require": {
        "1and1/1and1-sdk-php": ">=1.0.0"
    }
}

You will need to "autoload" the SDK by requiring Composer's autoload file at the top of your PHP script, like so:

<?php

require(__DIR__.'/vendor/autoload.php');

use src\oneandone\OneAndOne;

Note: An issue has been discoverd on Linux operating systems that prevents the SDK class from being autoloaded. After completing all of the steps above, you will need to run composer dumpautoload -o (global install), or php composer.phar dumpautoload -o (local install) from inside the directory that you originally ran composer install. Your file structure should look something like this:

/repo-root
  - composer.json
  - composer.lock
  - composer.phar (if you installed composer locally)
  - create_server.php
  - /vendor

After executing the dumpautoload command, you should then be able to run your create_server.php script.

Authentication

Connecting to 1&1 is handled by first setting up your authentication. Start your application by initializing the module with your API token.

<?php

require(__DIR__.'/vendor/autoload.php');

use src\oneandone\OneAndOne;

$client = new OneAndOne('<API-TOKEN>');

You can now use $client to perform all future operations.

Comments

Tags: PHP