PHP code example of transip / transip-api-symfony
1. Go to this page and download the library: Download transip/transip-api-symfony 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/ */
transip / transip-api-symfony example snippets
// src/Controller/TransIPApiController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Transip\Api\Library\TransipAPI;
class TransIPApiController
{
public function getVpses(
TransipAPI $apiClient
): Response {
// Get all VPSes for account #0 (authentication in config)
$apiClient->vps()->getAll();
// Authenticate client with Token (account #1)
$apiClient->setToken('some.jwt.token');
// Get all VPSes for account #1
$apiClient->vps()->getAll();
// Request Token with username and private key (account #2)
$token = $apiClient->auth()->createToken(
$transipUsername,
$transipPrivateKey,
false, // Create IP Whitelisted tokens
false, // Create a read only token
'' // Add Token label
'1 day' // Create token expire
);
// Set token in library
$apiClient->setToken($token);
// Get all VPSes for account #2
$apiClient->vps()->getAll();
}
}