PHP code example of fozzy-hosting / winvps-api-php

1. Go to this page and download the library: Download fozzy-hosting/winvps-api-php 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/ */

    

fozzy-hosting / winvps-api-php example snippets




ozzy\WinVPS\Api\Configuration;
use Fozzy\WinVPS\Api\Repository;
use Fozzy\WinVPS\Api\Models\MachineCreateRequestBody;

$host = 'Endpoint from API docs';
$key = 'API key from WinVPS client area';

try {
    // Create configuration object.
    $config = Configuration::getDefaultConfiguration()
        ->setHost($host)
        ->setApiKey($key);
    
    /*
    Create repository by passing the `config` instance.
    Repository allows to get an Instance for each class of API Endpoints described in docs foler. 
    */
    $repository = new Repository($config);
    
    // Get API Instance object to make requests. 
    $machinesInstance = $repository->get('machines');

    // Prepare request to create new machine.
    $body = new \Fozzy\WinVPS\Api\Models\MachineCreateRequestBody([
            'productId' => 17,
            'templateId' => 72,
            'locationId' => 1,
        ]);

    // Create new machine
    $machinesInstance->machinesPost($body);

    /*
    Load all machines from the endpoint.
    Only the part of records will be returned because API uses pagination
    */  
    $allMachinesPage = $machinesInstance->machinesGet();

    print_r($allMachinesPage);
    
} catch (Exception $e) {
    echo 'Exception when calling BrandsApi->brandsGet: ', $e->getMessage(), PHP_EOL;
}



/**
 * Each of the API Instances supports the next methods:
 *
 * paginationSetLimit($limit) - setup new per-page amount
 * paginationNext() - go to the next page
 * paginationPrev() - go to the previous page
 * paginationGetTotal() - total recourds amount
 * paginationGetPage() - get current page number
 * paginationGetPages() - get total pages count
 * paginationHasMore() - does the next page exists
 */

// Example based on the previous code
do {
    $allMachinesPage = $machinesInstance->machinesGet();
    $machinesInstance->paginationNext();

} while ($machinesInstance->paginationHasMore());