PHP code example of thg / thg-client

1. Go to this page and download the library: Download thg/thg-client 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/ */

    

thg / thg-client example snippets


    $thgHostingClient = new ThgHosting\ThgHostingClient($_ENV['X-Api-Token']);

    $thgHostingClient->request(
        string $method,         // Allowed methods: GET, POST, DELETE, PUT, PATCH
        string $endpoint,       // Path to chosen EP for example: "ssd-vps/plans"
        array $arguments = [],  // Body of request
        array $files     = [    // Files to send with request
            [
                // Mime type of file
                "mime" => "image/png",
                // Name of file
                "name" => "file.png",
                // Base64 encoded file
                "file" => "iVBORw0KGgoAAAANSUhEUgAAAIIAAABzCAYAAABUzdpBAAAIj0lEQVR4Xu2deVRVVRTGP0IN0QRRc8JQ0yy1XI7ZynRlTmmmYCUSKFm4HFFzKUY4g6VMag6..."
            ],
            "/path/to/file.pdf" // Absolute path to file
        ]
    );

    $thgHostingClient->getSsdVpsPlans();

    $thgHostingClient->getSsdVpsLocations();

    $thgHostingClient->getSsdVpsCustomTemplates(
        int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
    );

    $thgHostingClient->createSsdVpsServer(
        int     $locationId,              // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        string  $label,                   // Label for the new SSD VPS Server
        string  $hostname,                // Hostname for the new SSD VPS Server
        string  $productName,             // name of the chosen SSD VPS plan (see “Get SSD VPS Plans”)
        ?string $osComponentCode  = null, // Optional; Component code of the SSD VPS operating system (see “Get SSD VPS Operating Systems”) (you have to pass either os_component_code or custom_template_id)
        ?bool   $backups          = null, // Optional; If set to true, server will be created with Backup Protection
        ?bool   $billHourly       = null, // Optional; If set to true, billing will be set hourly, otherwise monthly billing will be used
        ?int    $customTemplateId = null  // Optional; Pass here the Template ID of Custom OS (see “Get Custom OSes for SSD VPS”) (you have to pass either os_component_code or custom_template_id)
    );

    $thgHostingClient->getSsdVpsOses(
        int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
    );

    $thgHostingClient->getSsdVpsServers(
        ?int $locationId = null // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
    );

    $thgHostingClient->getSsdVpsServerDetails(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->deleteSsdVpsServer(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server.
    );

    $thgHostingClient->getSsdVpsServerStatus(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->powerOnSsdVpsServer(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->powerOffSsdVpsServer(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->rebootSsdVpsServer(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->rebootSsdVpsServerInRecoveryMode(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->resetSsdVpsServerPassword(
        int     $locationId,        // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int     $serverId,          // ID of the SSD VPS Server
        ?string $newPassword = null // Root password to set. Must be between 6 and 32 characters and valid for the OS of the target virtual machine.
    );

    $thgHostingClient->getSsdVpsServerBackups(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId    // ID of the SSD VPS Server
    );

    $thgHostingClient->addSsdVpsBackupNote(
        int    $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int    $serverId,   // ID of the SSD VPS Server
        int    $backupId,   // ID of the SSD VPS Backup (see “Get SSD VPS Server Backups”)
        string $note        // Note
    );

    $thgHostingClient->deleteSsdVpsBackup(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId,   // ID of the SSD VPS Server
        int $backupId    // ID of the SSD VPS Backup (see “Get SSD VPS Server Backups”)
    );

    $thgHostingClient->restoreSsdVpsBackup(
        int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId,   // ID of the SSD VPS Server
        int $backupId    // ID of the SSD VPS Backup (see “Get SSD VPS Server Backups”)
    );

    $thgHostingClient->createBackup(
        int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId,  // ID of the SSD VPS Server
    );

    $thgHostingClient->ssdVpsIpRequest(
        int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”)
        int $serverId,  // ID of the SSD VPS Server
        string $reason, // Detailed explanation of why the IP is needed 
        array $ipCount  // Number of IP addresses to request in at least one of the following categories [terminal, vpn, mailing, application, voice, sqldb, ssl_cert, media, other]
    );

    $thgHostingClient->getServiceDetails(
        int $serviceId // ID of the Service
    );

    $thgHostingClient->getDnsZones();

    $thgHostingClient->createDnsZone(
        string $domainName, // Name of the domain
        string $ip          // IP address
    );

    $thgHostingClient->getDnsZoneDetails(
        int $zoneId // ID of the DNS Zone (see “Get DNS Zones”)
    );

    $thgHostingClient->deleteDnsZone(
        int $zoneId // ID of the DNS Zone (see “Get DNS Zones”)
    );

    $thgHostingClient->addRecordToDnsZone(
        int     $zoneId             // ID of the DNS Zone (see “Get DNS Zones”)
        string  $type,              // Zone type (A / AAAA etc.)
        string  $host,              // Host name or IP address
        string  $content,           // Content depending on the zone type, example: mail.hostname.com
        int     $ttl,               // Time to live - the added record or time to ping/fetch the updated records
        ?string $service    = null, // The symbolic name of the desired service. (only when record type SRV)
        ?string $protocol   = null, // The transport protocol of the desired service. (only when record type SRV)
        ?int    $port       = null, // The TCP or UDP port on which the service is to be found. (only when record type SRV)
        ?int    $weight     = null, // A relative weight for records with the same priority, higher value means higher chance of getting picked. (only when record type SRV)
        ?int    $mxPriority = null  // The priority of the target host, lower value means more preferred. (only when record type SRV or MX)
    );

    $thgHostingClient->updateDnsZoneRecord(
        int     $zoneId,            // ID of the DNS Zone (see “Get DNS Zones”)
        int     $recordId,          // ID of the DNS Zone record (see “Get DNS Zone Details”)
        string  $host,              // Host name or IP address
        string  $content,           // Content depending on the zone type, example: mail.hostname.com
        int     $ttl,               // Time to live - the added record or time to ping/fetch the updated records
        ?string $service    = null, // The symbolic name of the desired service. (only when record type SRV)
        ?string $protocol   = null, // The transport protocol of the desired service. (only when record type SRV)
        ?int    $port       = null, // The TCP or UDP port on which the service is to be found. (only when record type SRV)
        ?int    $weight     = null, // A relative weight for records with the same priority, higher value means higher chance of getting picked. (only when record type SRV)
        ?int    $mxPriority = null  // The priority of the target host, lower value means more preferred. (only when record type SRV or MX)
    );

    $thgHostingClient->deleteDnsZoneRecord(
        int $zoneId,  // ID of the DNS Zone (see “Get DNS Zones”)
        int $recordId // ID of the DNS Zone record
    );

    $thgHostingClient->getServers();

    $thgHostingClient->getServerDetails(
        string $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->getServerPowerStatus(
        string $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->powerOnServer(
        string $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->powerOffServer(
        string $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->rebootServer(
        string $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->changeServerFriendlyName(
        string $serverId, // ID of the Server (see “Get Servers”)
        $body
    );

    $thgHostingClient->changeServerFriendlyName(
        string $serverId, // ID of the Server (see “Get Servers”)
	string $ipAddress, //IP address the domain name should be associated with
        $body
    );

    $thgHostingClient->getServerSshKeys(
        string $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->assignServerSshKeys(
        string $serverId, // ID of the Server (see “Get Servers”)
        array $sshKeyIds  // array of SSH key ids to be assigned to the server
    );

    $thgHostingClient->unAssignServerSshKeys(
        string $serverId, // ID of the Server (see “Get Servers”)
        array $sshKeyIds  // array of SSH key ids to be un-assigned to the server
    );

    $thgHostingClient->setPxeUrl(
        string $serverId, // ID of the Server (see “Get Servers”)
        string $pxeScriptUrl  // URL to PXE script
    );

    $thgHostingClient->getServerBandwidthGraph(
        int    $serverId,           // ID of the Server (see “Get Servers”)
        string $periodStart = null, // Optional. And RFC3339/ISO8601 date-time string representing the start of period of the dataset. Defaults to the start of today.
        string $periodEnd   = null  // Optional. And RFC3339/ISO8601 date-time string representing the end of period of the dataset. Defaults to one month before the start of today
    );

    $thgHostingClient->bareMetalIpRequest(
        int $serverId,  // ID of the Bare Metal Server
        string $reason, // Detailed explanation of why the IP is needed 
        array $ipCount  // Number of IP addresses to request in at least one of the following categories [terminal, vpn, mailing, application, voice, sqldb, ssl_cert, media, other]
    );

    $thgHostingClient->getServerOsList(
        int $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->reimageServer(
        int    $serverId,       // ID of the Server (see “Get Servers”)
        string $osCode,         // Code of the OS to reimage the server with (see “Get Server OS List”)
        string $reason = null   // Optional. Reason for reimage
    );

    $thgHostingClient-getServerIPMIDetails(
        int $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient-createServerIPMICredentials(
        int $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient-deleteServerIPMICredentials(
        int $serverId // ID of the Server (see “Get Servers”)
    );

    $thgHostingClient->addBandwidth(
        int $locationId //Bandwidth location ID
        int $quantity  // Quantity of bandwidth to add (in TB)
    );

    $thgHostingClient->getTickets();

    $thgHostingClient->createTicket(
        string $body,            // Ticket body
        string $subject,         // Subject
        int    $department  = 0, // Ticket Department - Default: 0 (General)
        int    $priority    = 0, // Priority of a Ticket (Default: 0 = Low, 1= Normal, 2 = High, 3 = Urgent)
        array  $attachments = [] // How to attach files you can find described in `request` method
    );

    $thgHostingClient->getTicketDepartments();

    $thgHostingClient->getTicketDetails(
        int $ticketId // ID of the ticket (see “Get Tickets”)
    );

    $thgHostingClient->updateTicket(
        int  $ticketId,           // ID of the ticket (see “Get Tickets”)
        int  $priority    = 0,    // Priority of a Ticket (Default: 0 = Low, 1= Normal, 2 = High, 3 = Urgent)
        bool $closeTicket = false // Set to true will close the ticket
    );

    $thgHostingClient->addReplyToTicket(
        int    $ticketId,        // ID of the ticket (see “Get Tickets”)
        string $body,            // Ticket body
        array  $attachments = [] // How to attach files you can find described in `request` method
    );

    $thgHostingClient->getStatusUpdates();

    $thgHostingClient->getBillingServices(
        ?bool $showAddOns,  //Show the add-ons belonging to each service
        ?string $sortBy,    //Sort by column (service_id/createdon)
        ?string $direction, //Sort direction (default asc)
        ?int $offset,       //If set, returns records starting from this offset
        ?int $limit         //If set, limits the number of records
    );

    $thgHostingClient->getBillingInvoices(
        ?int $offset,       //If set, returns records starting from this offset
        ?int $limit         //If set, limits the number of records
    );

    $thgHostingClient->getMicrosoftLicenses(
        int $serviceId,      // Server service ID to get a list of licenses
    );

    $thgHostingClient->getMicrosoftLicenseDetails(
        int $serviceId,      // Server service ID for retrieving of an MS license details which belongs to
        int $licenseId,      // License ID to get an MS license details
    );

    $thgHostingClient->deleteMicrosoftLicense(
        int $serviceId,      // Server service ID for deleting of an MS license which belongs to
        int $licenseId,      // License ID to delete
    );

    $thgHostingClient->getMicrosoftLicenseProducts(
        int $serviceId,      // Server service ID to get a list of license products
    );

    $thgHostingClient->listSshKeys();

    $thgHostingClient->createSshKey(
        string $key,        // Public RSA Key to be stored
        string $label,      // Label for SSH Key
    );

    $thgHostingClient->updateSshKeyLabel(
        int $sshId,         // The ID for the SSH Key to be updated
        string $label,      // The new label for the SSH Key
    );

    $thgHostingClient->deleteSshKey(
        int $sshId,         // The ID of the SSH Key to be deleted
    );
    );

    $thgHostingClient->getSshKeyById(
        int $sshId,      // The ID of the SSH Key to be fetched
    );

    $thgHostingClient->getServerInventory(
        ?int $datacenterId = null,
        ?string $cpuBrand = null,
        ?int $minCpuCores = null,
        ?int $maxCpuCores = null,
        ?float $minCpuSpeed = null,
        ?float $maxCpuSpeed = null,
        ?int $minRam = null,
        ?int $maxRam = null,
        ?string $storageType = null,
        ?int $minStorage = null,
        ?int $maxStorage = null,
        ?int $minNic = null,
        ?int $maxNic = null,
        ?float $minPrice = null,
        ?float $maxPrice = null,
        ?bool $raidEnabled = null,
        ?string $sortBy = null,
        ?string $direction = null
    );

    $thgHostingClient->createBareMetalServerOrder(
        string $skuProductName,
        int $quantity,
        string $locationCode,
        string $operatingSystemProductCode,      //Find available OS product codes by calling the list addons endpoint
        ?string $licenseProductCode = null,      //Find available license product codes by calling the list addons endpoint
        ?int $additionalBandwidthTb = null, 
        ?string $supportLevelProductCode = null, //Find available managed support product codes by calling the list addons endpoint
        ?array $sshKeyIds = null                 //Add ssh keys to the server.
    );

    $thgHostingClient->listAvailableBareMetalAddons(
        string $skuProductName, 
        string $locationCode
    );