thg / thg-client
THG Open API client
Requires
- php: ^7.2 || ^8.0
- ext-curl: *
- ext-fileinfo: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.5
README
PHP Client for easier use of Open API
$thgHostingClient = new ThgHosting\ThgHostingClient($_ENV['X-Api-Token']);
Install
composer require thg/thg-client
Methods
Request
Creates custom request to chosen EP.
$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 ] );
Get SSD VPS Plans
Returns SSD VPS Plans with net price in USD.
$thgHostingClient->getSsdVpsPlans();
Get SSD VPS Locations
Returns SSD VPS Locations.
$thgHostingClient->getSsdVpsLocations();
Get Custom OSes for SSD VPS
Returns Custom OSes for SSD VPS.
$thgHostingClient->getSsdVpsCustomTemplates( int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”) );
Create an SSD VPS Server
Creates an SSD VPS Server.
$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) );
Get SSD VPS Operating Systems
Returns SSD VPS Operating Systems.
$thgHostingClient->getSsdVpsOses( int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”) );
Get SSD VPS Servers
Returns SSD VPS Servers.
$thgHostingClient->getSsdVpsServers( ?int $locationId = null // ID of the SSD VPS Location (see “Get SSD VPS Locations”) );
Get SSD VPS Server Details
Returns an SSD VPS Server’s details.
$thgHostingClient->getSsdVpsServerDetails( int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”) int $serverId // ID of the SSD VPS Server );
Delete SSD VPS Server
Deletes an 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. );
Get SSD VPS Server Status
Returns an SSD VPS Server’s status.
$thgHostingClient->getSsdVpsServerStatus( int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”) int $serverId // ID of the SSD VPS Server );
Power On an SSD VPS Server
Startup an 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 );
Power Off SSD VPS Server
Shutdown an 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 );
Reboot SSD VPS Server
Reboot an 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 );
Reboot an SSD VPS Server in Recovery Mode
Reboot an SSD VPS in Recovery Mode.
$thgHostingClient->rebootSsdVpsServerInRecoveryMode( int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”) int $serverId // ID of the SSD VPS Server );
Reset Password of an SSD VPS Server
Change the virtual machine’s root password to regain control of a machine should root access be lost or forgotten.
$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. );
Get SSD VPS Server Backups
Returns an SSD VPS Server’s Backups.
$thgHostingClient->getSsdVpsServerBackups( int $locationId, // ID of the SSD VPS Location (see “Get SSD VPS Locations”) int $serverId // ID of the SSD VPS Server );
Add Note to an SSD VPS Server Backup
Add note to an SSD VPS Server’s backup.
$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 );
Delete SSD VPS Server Backup
Deletes an SSD VPS Server’s Backup.
$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”) );
Restore SSD VPS Server with Backup
Restore an SSD VPS Backup. (Overwrites existing SSD VPS with backed up image).
$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”) );
Create Backups
Create SSD VPS Backups
$thgHostingClient->createBackup( int $locationId // ID of the SSD VPS Location (see “Get SSD VPS Locations”) int $serverId, // ID of the SSD VPS Server );
Create IP Request
Request a new IP address.
$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] );
Get Service Details
Get details for a service with net price in USD.
$thgHostingClient->getServiceDetails( int $serviceId // ID of the Service );
Get DNS Zones
Get all DNS zones.
$thgHostingClient->getDnsZones();
Create DNS Zone
Create a DNS zone.
$thgHostingClient->createDnsZone( string $domainName, // Name of the domain string $ip // IP address );
Get DNS Zone Details
Get DNS zone information.
$thgHostingClient->getDnsZoneDetails( int $zoneId // ID of the DNS Zone (see “Get DNS Zones”) );
Delete DNS Zone
Remove a DNS zone.
$thgHostingClient->deleteDnsZone( int $zoneId // ID of the DNS Zone (see “Get DNS Zones”) );
Add Record to DNS Zone
Adds a DNS record to the specified zone.
$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) );
Update DNS Zone Record
Update an existing DNS zone record.
$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) );
Delete DNS Zone Record
Remove a DNS record.
$thgHostingClient->deleteDnsZoneRecord( int $zoneId, // ID of the DNS Zone (see “Get DNS Zones”) int $recordId // ID of the DNS Zone record );
Get Servers
Get a list of all servers assigned to an account.
$thgHostingClient->getServers();
Get Server Details
Get full server profile.
$thgHostingClient->getServerDetails( string $serverId // ID of the Server (see “Get Servers”) );
Get Server Power Status
Retrieve the current power state of the given dedicated server.
$thgHostingClient->getServerPowerStatus( string $serverId // ID of the Server (see “Get Servers”) );
Power On Server
Request the specified dedicated server to be turned on.
$thgHostingClient->powerOnServer( string $serverId // ID of the Server (see “Get Servers”) );
Power Off Server
Request the specified dedicated server to be turned off.
$thgHostingClient->powerOffServer( string $serverId // ID of the Server (see “Get Servers”) );
Reboot Server
Request the specified dedicated server to be rebooted.
$thgHostingClient->rebootServer( string $serverId // ID of the Server (see “Get Servers”) );
Change Server Friendly Name
Request friendly name change of specified dedicated server.
$thgHostingClient->changeServerFriendlyName( string $serverId, // ID of the Server (see “Get Servers”) $body );
Set rDNS entry for IP address
Set rDNS entry for IP address of specified dedicated server.
$thgHostingClient->changeServerFriendlyName( string $serverId, // ID of the Server (see “Get Servers”) string $ipAddress, //IP address the domain name should be associated with $body );
get SSH keys assigned to a server
Get list of SSH keys currently assigned to given server.
$thgHostingClient->getServerSshKeys( string $serverId // ID of the Server (see “Get Servers”) );
assign SSH key(s) to servers
Assign one or more SSH keys to given server.
$thgHostingClient->assignServerSshKeys( string $serverId, // ID of the Server (see “Get Servers”) array $sshKeyIds // array of SSH key ids to be assigned to the server );
un-assign SSH key(s) to servers
Un-assign one or more SSH keys from given 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 );
Set a custom PXE boot URL
Specify a custom PXE boot URL to load your preferred network boot environment.
$thgHostingClient->setPxeUrl( string $serverId, // ID of the Server (see “Get Servers”) string $pxeScriptUrl // URL to PXE script );
Get Server Bandwidth Graph
Get a graphical representation of the bandwidth usage for a specific server over the given period.
$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 );
Create IP Request
Request a new IP address
$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] );
Get Server OS List
Get a list of available operating systems for provisioning a specific server.
$thgHostingClient->getServerOsList( int $serverId // ID of the Server (see “Get Servers”) );
Reimage Server
Reimage a server with a new operating system.
$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 );
Get IPMI details for server
Get IPMI details for server.
$thgHostingClient-getServerIPMIDetails( int $serverId // ID of the Server (see “Get Servers”) );
Create VPN user to access IPMI interface
Create VPN user to access IPMI interface.
$thgHostingClient-createServerIPMICredentials( int $serverId // ID of the Server (see “Get Servers”) );
Delete VPN access to IPMI interface
Delete VPN access to IPMI interface.
$thgHostingClient-deleteServerIPMICredentials( int $serverId // ID of the Server (see “Get Servers”) );
Add Backup to Bare Metal Servers
Add Bandwidth
$thgHostingClient->addBandwidth( int $locationId //Bandwidth location ID int $quantity // Quantity of bandwidth to add (in TB) );
Get Tickets
Get a list of active support tickets.
$thgHostingClient->getTickets();
Create Ticket
Create a new support ticket.
$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 );
Get Ticket Departments
Get a list of ticket queues by department.
$thgHostingClient->getTicketDepartments();
Get Ticket Details
Get the details of a specified support ticket.
$thgHostingClient->getTicketDetails( int $ticketId // ID of the ticket (see “Get Tickets”) );
Update Ticket
Update status of existing support ticket.
$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 );
Add Reply to Ticket
Add reply to a specific support 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 );
Get Status Updates
Get a list of active status updates.
$thgHostingClient->getStatusUpdates();
Get Billing Services
Returns customer services.
$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 );
Get Billing Invoices
Returns customer invoices.
$thgHostingClient->getBillingInvoices( ?int $offset, //If set, returns records starting from this offset ?int $limit //If set, limits the number of records );
Get Microsoft Licenses
Returns Microsoft Licenses
$thgHostingClient->getMicrosoftLicenses( int $serviceId, // Server service ID to get a list of licenses );
Get Microsoft License Details
Returns Microsoft License Details
$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 );
Delete Microsoft License
Deletes a Microsoft License
$thgHostingClient->deleteMicrosoftLicense( int $serviceId, // Server service ID for deleting of an MS license which belongs to int $licenseId, // License ID to delete );
Get Available Microsoft License Products
Returns A List Of Microsoft License Products
$thgHostingClient->getMicrosoftLicenseProducts( int $serviceId, // Server service ID to get a list of license products );
List SSH keys Data
Returns A List Of SSH Keys
$thgHostingClient->listSshKeys();
Add An SSH Key
Creates New SSH Key Record
$thgHostingClient->createSshKey( string $key, // Public RSA Key to be stored string $label, // Label for SSH Key );
Update Label For An Existing SSH Key
Updates Label For SSH Key Given Id
$thgHostingClient->updateSshKeyLabel( int $sshId, // The ID for the SSH Key to be updated string $label, // The new label for the SSH Key );
Delete An SSH Key
Delete An SSH Key Of The Given Id
$thgHostingClient->deleteSshKey( int $sshId, // The ID of the SSH Key to be deleted ); );
Get An SSH Key With Id
Returns An SSH Key Given Id
$thgHostingClient->getSshKeyById( int $sshId, // The ID of the SSH Key to be fetched );
Get list of server inventory
Returns server inventory list
$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 );
Create new bare metal server order
Creates new bare metal server order
$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. );
List Available addons for bare metal server order
Returns list of all available addons for a bare metal server
$thgHostingClient->listAvailableBareMetalAddons( string $skuProductName, string $locationCode );