### POST /vps Source: https://context7.com/transip/transip-api-php/llms.txt Order new VPS instances and perform control operations like start, stop, and reset. ```APIDOC ## POST /vps ### Description Order a new VPS instance with specific configuration or perform lifecycle operations on existing instances. ### Method POST ### Endpoint /vps ### Request Body - **productName** (string) - Required - The product identifier - **operatingSystem** (string) - Required - The OS to install - **hostname** (string) - Optional - Server hostname - **availabilityZone** (string) - Optional - Data center zone ### Response #### Success Response (200) - **status** (string) - Operation status ### Response Example { "status": "success" } ``` -------------------------------- ### Install TransIP API PHP Library with Composer Source: https://github.com/transip/transip-api-php/blob/master/README.md This snippet shows the command to install the TransIP API PHP library using Composer, a dependency manager for PHP. It ensures that the library and its dependencies are correctly set up for your project. ```bash composer require transip/transip-api-php ``` -------------------------------- ### GET /vps Source: https://context7.com/transip/transip-api-php/llms.txt Retrieve information about your VPS instances including specifications, status, and IP addresses. ```APIDOC ## GET /vps ### Description Retrieve a list of all VPS instances or specific instances by name, identifier, or tags. ### Method GET ### Endpoint /vps ### Parameters #### Query Parameters - **page** (int) - Optional - Page number for pagination - **itemsPerPage** (int) - Optional - Number of items per page ### Response #### Success Response (200) - **vpsList** (array) - List of VPS objects containing name, uuid, status, and specs. ### Response Example { "vps": [ { "name": "vps-name", "uuid": "abc12345-uuid", "status": "running", "ipAddress": "1.2.3.4" } ] } ``` -------------------------------- ### List and Get VPS Instances with PHP Source: https://context7.com/transip/transip-api-php/llms.txt Retrieve a list of all VPS instances, paginated results, or specific VPS by name, UUID, or tags. This function requires access to the TransIP API client. ```php vps()->getAll(); foreach ($vpsList as $vps) { echo "VPS: " . $vps->getName() . "\n"; echo " UUID: " . $vps->getUuid() . "\n"; echo " Product: " . $vps->getProductName() . "\n"; echo " OS: " . $vps->getOperatingSystem() . "\n"; echo " Status: " . $vps->getStatus() . "\n"; echo " IP: " . $vps->getIpAddress() . "\n"; echo " CPUs: " . $vps->getCpus() . "\n"; echo " Memory: " . $vps->getMemorySize() . " MB\n"; echo " Disk: " . $vps->getDiskSize() . " GB\n"; echo " Zone: " . $vps->getAvailabilityZone() . "\n"; echo " Is Locked: " . ($vps->isLocked() ? 'Yes' : 'No') . "\n"; } // Get VPS with pagination $vpsPaginated = $api->vps()->getSelection($page = 1, $itemsPerPage = 10); // Get a specific VPS by name or UUID $vps = $api->vps()->getByName('vps-name'); $vps = $api->vps()->getByIdentifier('abc12345-uuid'); // Get VPS by tags $taggedVps = $api->vps()->getByTagNames(['web-server', 'production']); ``` -------------------------------- ### Authenticate with TransIP API Source: https://context7.com/transip/transip-api-php/llms.txt Initialize the TransIPAPI client using your login credentials and private key. This setup includes optional token caching and configuration for read-only modes or token expiry. ```php test()->test()) { echo 'API connection successful!'; } $api->setReadOnlyMode(true); $api->setTokenExpiryTime('1 day'); ``` -------------------------------- ### Order and Control VPS Instances with PHP Source: https://context7.com/transip/transip-api-php/llms.txt Order new VPS instances with basic or full configuration, order multiple VPS, clone existing ones, and perform control operations like start, stop, and reset. Updates to VPS descriptions, tags, and lock status are also supported. This function requires access to the TransIP API client. ```php vps()->order($productName, $operatingSystem); // Order VPS with full configuration $productName = 'vps-bladevps-x4'; $operatingSystem = 'debian-12'; $addons = ['vpsAddon-1-extra-ip-address', 'vpsAddon-1-extra-cpu-core']; $hostname = 'server.example.com'; $availabilityZone = 'ams0'; // ams0, rtm0, etc. $description = 'Production web server'; $base64InstallText = ''; // Optional base64-encoded install script $installFlavour = 'cloudinit'; // 'cloudinit' or 'installer' $username = 'admin'; $sshKeys = ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQ...']; $licenses = []; $hashedPassword = ''; $response = $api->vps()->order( $productName, $operatingSystem, $addons, $hostname, $availabilityZone, $description, $base64InstallText, $installFlavour, $username, $sshKeys, $licenses, $hashedPassword ); // Order multiple VPS at once $vpss = [ [ 'productName' => 'vps-bladevps-x1', 'operatingSystem' => 'ubuntu-22.04', 'availabilityZone' => 'ams0', 'description' => 'Load balancer 1' ], [ 'productName' => 'vps-bladevps-x1', 'operatingSystem' => 'ubuntu-22.04', 'availabilityZone' => 'rtm0', 'description' => 'Load balancer 2' ] ]; $api->vps()->orderMultiple($vpss); // Clone an existing VPS $api->vps()->cloneVps('source-vps-name', 'ams0'); // Start, stop, and reset VPS $api->vps()->start('vps-name'); $api->vps()->stop('vps-name'); $api->vps()->reset('vps-name'); // Update VPS (description, tags, lock status) $vps = $api->vps()->getByName('vps-name'); $vps->setDescription('Updated description'); $vps->addTag('production'); $vps->setIsCustomerLocked(true); $api->vps()->update($vps); // Handover VPS to another customer $api->vps()->handover('vps-name', 'target-customer-login'); // Cancel VPS (endTime: 'end' or 'immediately') $api->vps()->cancel('vps-name', 'end'); ``` -------------------------------- ### Manage Block Storage with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This snippet shows how to manage block storage volumes for VPS instances using the TransIP API PHP SDK. It covers retrieving all block storages, paginated retrieval, getting a storage by name, ordering new storage, upgrading existing storage, updating storage descriptions, canceling storage, retrieving storage backups, and getting usage statistics. The TransIP API client is a key dependency. ```php blockStorages()->getAll(); foreach ($blockStorages as $storage) { echo "Name: " . $storage->getName() . "\n"; echo " Size: " . $storage->getSize() . " GB\n"; echo " Status: " . $storage->getStatus() . "\n"; echo " Attached VPS: " . ($storage->getVpsName() ?: 'None') . "\n"; echo " Zone: " . $storage->getAvailabilityZone() . "\n"; } // Get block storage with pagination $paginatedStorage = $api->blockStorages()->getSelection($page = 1, $itemsPerPage = 10); // Get specific block storage by name $storage = $api->blockStorages()->getByName('storage-name'); // Order new block storage $type = 'fast-storage'; // Storage type $size = '100'; // Size in GB $offsiteBackup = true; // Enable offsite backups $availabilityZone = 'ams0'; $vpsName = 'my-vps'; // Optionally attach to VPS $description = 'Database storage'; $api->blockStorages()->order($type, $size, $offsiteBackup, $availabilityZone, $vpsName, $description); // Upgrade block storage size $api->blockStorages()->upgrade('storage-name', 200, true); // New size, offsite backups // Update block storage (description) $storage = $api->blockStorages()->getByName('storage-name'); $storage->setDescription('Updated description'); $api->blockStorages()->update($storage); // Cancel block storage $api->blockStorages()->cancel('storage-name', 'end'); // 'end' or 'immediately' // Get block storage backups $backups = $api->blockStorageBackups()->getByBlockStorageName('storage-name'); // Get block storage usage statistics $usage = $api->blockStorageUsage()->getByBlockStorageName('storage-name'); ``` -------------------------------- ### Manage SSH Keys with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This snippet demonstrates how to manage SSH keys for VPS provisioning using the TransIP API PHP SDK. It includes functions to retrieve all SSH keys, retrieve keys with pagination, get a specific key by ID, create a new SSH key, update an existing key's description, and delete an SSH key. The primary dependency is the TransIP API client. ```php sshKey()->getAll(); foreach ($sshKeys as $key) { echo "Key ID: " . $key->getId() . "\n"; echo " Description: " . $key->getDescription() . "\n"; echo " Fingerprint: " . $key->getFingerprint() . "\n"; echo " Is Default: " . ($key->getIsDefault() ? 'Yes' : 'No') . "\n"; } // Get SSH keys with pagination $sshKeysPaginated = $api->sshKey()->getSelection($page = 1, $itemsPerPage = 25); // Get a specific SSH key by ID $sshKey = $api->sshKey()->getById('12345'); // Create a new SSH key $publicKey = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC...'; $description = 'My laptop key'; $isDefault = true; // Use this key by default for new VPS $api->sshKey()->create($publicKey, $description, $isDefault); // Update SSH key description $sshKeyId = 12345; $api->sshKey()->update($sshKeyId, 'Updated description'); // Delete SSH key $api->sshKey()->delete($sshKeyId); ``` -------------------------------- ### Manage Private Networks with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This snippet demonstrates how to manage private networks using the TransIP API in PHP. It covers fetching all networks, getting a specific network by name, finding networks by description, ordering new networks, updating existing ones, and attaching/detaching VPS instances. It requires the TransIP API client library for PHP. ```php privateNetworks()->getAll(); foreach ($networks as $network) { echo "Name: " . $network->getName() . "\n"; echo " Description: " . $network->getDescription() . "\n"; echo " Zone: " . $network->getAvailabilityZone() . "\n"; } // Get specific private network $network = $api->privateNetworks()->getByName('network-name'); // Find networks by description $matchingNetworks = $api->privateNetworks()->findByDescription('Production network'); // Order a new private network $api->privateNetworks()->order('My private network'); // Update private network $network = $api->privateNetworks()->getByName('network-name'); $network->setDescription('Updated description'); $api->privateNetworks()->update($network); // Attach VPS to private network $api->privateNetworks()->attachVps('network-name', 'vps-name'); // Detach VPS from private network $api->privateNetworks()->detachVps('network-name', 'vps-name'); // Cancel private network $api->privateNetworks()->cancel('network-name', 'end'); ``` -------------------------------- ### Get All Domains using TransIP API PHP Source: https://github.com/transip/transip-api-php/blob/master/README.md This PHP code snippet shows how to retrieve a list of all domains associated with your TransIP account using the TransIP API Library. It assumes you have already authenticated and have an active API instance. ```php $allDomains = $api->domains()->getAll(); ``` -------------------------------- ### List Products, Availability Zones, and OS - PHP Source: https://context7.com/transip/transip-api-php/llms.txt Retrieves and displays information about available products, availability zones, and operating systems for VPS. It also demonstrates checking domain name availability and listing available TLDs. No external dependencies beyond the TransIP API client. ```php products()->getAll(); foreach ($products as $product) { echo "Product: " . $product->getName() . "\n"; echo " Description: " . $product->getDescription() . "\n"; echo " Price: " . $product->getPrice() . "\n"; } // Get availability zones $zones = $api->availabilityZone()->getAll(); foreach ($zones as $zone) { echo "Zone: " . $zone->getName() . "\n"; echo " Country: " . $zone->getCountry() . "\n"; echo " Is default: " . ($zone->getIsDefault() ? 'Yes' : 'No') . "\n"; } // Get available operating systems for VPS $operatingSystems = $api->vpsOperatingSystems()->getAll(); foreach ($operatingSystems as $os) { echo "OS: " . $os->getName() . "\n"; echo " Description: " . $os->getDescription() . "\n"; echo " Is preinstallable: " . ($os->getIsPreinstallableImage() ? 'Yes' : 'No') . "\n"; } // Check domain availability $result = $api->domainAvailability()->checkAvailable('example.nl'); echo "Domain status: " . $result->getStatus() . "\n"; // free, inyouraccount, notfree // Check multiple domains $results = $api->domainAvailability()->checkAvailableMultiple(['domain1.nl', 'domain2.com', 'domain3.eu']); // Get available TLDs $tlds = $api->domainTlds()->getAll(); foreach ($tlds as $tld) { echo "TLD: " . $tld->getName() . "\n"; echo " Price: " . $tld->getPrice() . "\n"; echo " Renewal price: " . $tld->getRenewalPrice() . "\n"; } ``` -------------------------------- ### Manage VPS Backups and Snapshots with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This snippet demonstrates how to manage VPS backups and snapshots using the TransIP API PHP SDK. It covers retrieving backups and snapshots, reverting to a backup, converting backups to snapshots, creating new snapshots, reverting to snapshots, and deleting snapshots. Dependencies include the TransIP API client. ```php vpsBackups()->getByVpsName($vpsName); foreach ($backups as $backup) { echo "Backup ID: " . $backup->getId() . "\n"; echo " Date: " . $backup->getDateTimeCreate() . "\n"; echo " Disk size: " . $backup->getDiskSize() . " GB\n"; echo " OS: " . $backup->getOperatingSystem() . "\n"; echo " Status: " . $backup->getStatus() . "\n"; } // Revert VPS to a backup $backupId = 12345; $api->vpsBackups()->revertBackup($vpsName, $backupId); // Convert backup to snapshot $api->vpsBackups()->convertToSnapshot($vpsName, $backupId, 'Snapshot description'); // Get all snapshots $snapshots = $api->vpsSnapshots()->getByVpsName($vpsName); foreach ($snapshots as $snapshot) { echo "Snapshot: " . $snapshot->getName() . "\n"; echo " Description: " . $snapshot->getDescription() . "\n"; echo " Created: " . $snapshot->getDateTimeCreate() . "\n"; } // Create a new snapshot $api->vpsSnapshots()->createSnapshot($vpsName, 'Pre-upgrade snapshot'); // Revert to snapshot $snapshotName = 'snapshot-name'; $api->vpsSnapshots()->revertSnapshot($vpsName, $snapshotName); // Delete snapshot $api->vpsSnapshots()->deleteSnapshot($vpsName, $snapshotName); ``` -------------------------------- ### Manage Domain Registration and Transfers with PHP Source: https://context7.com/transip/transip-api-php/llms.txt Demonstrates how to register new domains, transfer existing ones, cancel subscriptions, and perform domain handovers. It requires the TransIP API library and utilizes WhoisContact and DnsEntry entities for configuration. ```php domains()->register('mynewdomain.nl'); // Register with custom contacts $registrant = new WhoisContact([ 'type' => 'registrant', 'firstName' => 'John', 'lastName' => 'Doe', 'companyName' => 'Example Corp', 'companyKvk' => '12345678', 'companyType' => 'BV', 'street' => 'Example Street 123', 'postalCode' => '1234AB', 'city' => 'Amsterdam', 'phoneNumber' => '+31612345678', 'email' => 'john@example.com', 'country' => 'nl' ]); $nameservers = [ new Nameserver(['hostname' => 'ns0.transip.nl', 'ipv4' => '', 'ipv6' => '']), new Nameserver(['hostname' => 'ns1.transip.nl', 'ipv4' => '', 'ipv6' => '']), new Nameserver(['hostname' => 'ns2.transip.nl', 'ipv4' => '', 'ipv6' => '']) ]; $dnsEntries = [ new DnsEntry(['name' => '@', 'expire' => 300, 'type' => 'A', 'content' => '37.97.254.1']), new DnsEntry(['name' => 'www', 'expire' => 300, 'type' => 'CNAME', 'content' => '@']) ]; $api->domains()->register('mynewdomain.nl', [$registrant], $nameservers, $dnsEntries); // Transfer a domain from another registrar $authCode = 'ABC123XYZ'; $api->domains()->transfer('existingdomain.com', $authCode, [$registrant], $nameservers, $dnsEntries); // Cancel a domain (endTime: 'end' or 'immediately') $api->domains()->cancel('mynewdomain.nl', 'end'); // Handover domain to another TransIP customer $api->domains()->handover('mynewdomain.nl', 'target-customer-login'); ``` -------------------------------- ### Configure VPS Firewall Rules with PHP Source: https://context7.com/transip/transip-api-php/llms.txt Retrieve the current firewall configuration for a VPS and create new firewall rules for specific protocols, ports, and IP whitelists. This function requires the TransIP API client and the FirewallRule entity. ```php vpsFirewall()->getByVpsName($vpsName); echo "Firewall enabled: " . ($firewall->getIsEnabled() ? 'Yes' : 'No') . "\n"; foreach ($firewall->getRuleSet() as $rule) { echo sprintf( "Rule: %s - Port %d-%d/%s\n", $rule->getDescription(), $rule->getStartPort(), $rule->getEndPort(), $rule->getProtocol() ); } // Create firewall rules $httpRule = new FirewallRule(); $httpRule->setDescription('HTTP'); $httpRule->setStartPort(80); $httpRule->setEndPort(80); $httpRule->setProtocol('tcp'); $httpRule->setWhitelist([]); // Empty = allow all $httpsRule = new FirewallRule(); $httpsRule->setDescription('HTTPS'); $httpsRule->setStartPort(443); $httpsRule->setEndPort(443); $httpsRule->setProtocol('tcp'); $httpsRule->setWhitelist([]); $sshRule = new FirewallRule(); $sshRule->setDescription('SSH'); $sshRule->setStartPort(22); $sshRule->setEndPort(22); $sshRule->setProtocol('tcp'); $sshRule->setWhitelist(['203.0.113.0/24', '198.51.100.5']); // Restrict to specific IPs // Add rules to firewall $firewall->addRule($httpRule); $firewall->addRule($httpsRule); $firewall->addRule($sshRule); // Apply firewall changes $api->vpsFirewall()->update($vpsName, $firewall); ``` -------------------------------- ### Manage Invoices with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This PHP code snippet demonstrates how to retrieve invoice information and download PDF copies using the TransIP API. It covers fetching all invoices, paginated selections, specific invoices by number, and invoice items. It also shows how to download an invoice as a PDF and save it to a file. The TransIP API client library is required. ```php invoice()->getAll(); foreach ($invoices as $invoice) { echo "Invoice: " . $invoice->getInvoiceNumber() . "\n"; echo " Date: " . $invoice->getCreationDate() . "\n"; echo " Due date: " . $invoice->getDueDate() . "\n"; echo " Amount: " . $invoice->getTotalAmount() . "\n"; echo " Status: " . $invoice->getInvoiceStatus() . "\n"; } // Get invoices with pagination $paginatedInvoices = $api->invoice()->getSelection($page = 1, $itemsPerPage = 25); // Get specific invoice $invoice = $api->invoice()->getByInvoiceNumber('F12345'); // Get invoice items $items = $api->invoiceItem()->getByInvoiceNumber('F12345'); foreach ($items as $item) { echo " - " . $item->getDescription() . ": " . $item->getAmount() . "\n"; } // Download invoice as PDF $pdf = $api->invoicePdf()->getByInvoiceNumber('F12345'); file_put_contents('invoice-F12345.pdf', base64_decode($pdf->getPdf())); ``` -------------------------------- ### Manage Kubernetes Clusters with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This snippet illustrates the management of Kubernetes clusters via the TransIP API using PHP. It includes operations for retrieving clusters, creating new ones with specified versions and node configurations, updating cluster details, upgrading Kubernetes versions, and managing node pools, nodes, taints, and labels. It also covers advanced features like blocking mail ports, handing over clusters, and deleting them. The `TransipApiLibraryEntityKubernetesTaint` class is used for taint management. ```php kubernetesClusters()->getAll(); foreach ($clusters as $cluster) { echo "Cluster: " . $cluster->getName() . "\n"; echo " Description: " . $cluster->getDescription() . "\n"; echo " K8s Version: " . $cluster->getKubernetesVersion() . "\n"; echo " Status: " . $cluster->getStatus() . "\n"; } // Get a specific cluster $cluster = $api->kubernetesClusters()->getByName('cluster-name'); // Create a new Kubernetes cluster $api->kubernetesClusters()->create( '1.28', // Kubernetes version 'Production cluster', 'k8s-node-x4', // Node specification 3, // Number of nodes 'ams0' // Availability zone ); // Update cluster description $cluster->setDescription('Updated description'); $api->kubernetesClusters()->updateCluster($cluster); // Upgrade Kubernetes version $api->kubernetesClusters()->upgrade('cluster-name', '1.29'); // Get cluster kubeconfig $kubeConfig = $api->kubernetesKubeConfig()->getByClusterName('cluster-name'); echo $kubeConfig->getYamlConfig(); // Manage node pools $nodePools = $api->kubernetesNodePools()->getAll('cluster-name'); foreach ($nodePools as $pool) { echo "Node Pool: " . $pool->getUuid() . "\n"; echo " Nodes: " . $pool->getDesiredNodeCount() . "\n"; } // Get nodes in a cluster $nodes = $api->kubernetesNodes()->getAll('cluster-name'); // Manage taints on node pools $clusterName = 'my-cluster'; $nodePoolUuid = 'pool-uuid'; $taints = $api->kubernetesTaints()->getAll($clusterName, $nodePoolUuid); // Add a new taint $taints[] = new Taint([ 'key' => 'dedicated', 'value' => 'gpu', 'effect' => 'NoSchedule' // NoSchedule, PreferNoSchedule, NoExecute ]); $api->kubernetesTaints()->update($clusterName, $nodePoolUuid, $taints); // Manage labels $labels = $api->kubernetesLabels()->getAll($clusterName, $nodePoolUuid); // Block/unblock mail ports $api->kubernetesClusters()->blockMailPorts('cluster-name'); $api->kubernetesClusters()->unblockMailPorts('cluster-name'); // Handover cluster to another customer $api->kubernetesClusters()->handover('cluster-name', 'target-customer'); // Delete cluster $api->kubernetesClusters()->remove('cluster-name'); ``` -------------------------------- ### Manage HA-IPs with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This PHP snippet demonstrates how to manage High Availability IPs (HA-IPs) for load balancing and failover using the TransIP API. It includes operations for retrieving, ordering, updating, and canceling HA-IPs, as well as managing associated port configurations, status reports, and certificates. The TransIP API client library is a prerequisite. ```php haip()->getAll(); foreach ($haips as $haip) { echo "HA-IP: " . $haip->getName() . "\n"; echo " IP: " . $haip->getIpv4Address() . "\n"; echo " IPv6: " . $haip->getIpv6Address() . "\n"; echo " Status: " . $haip->getStatus() . "\n"; echo " Description: " . $haip->getDescription() . "\n"; } // Get HA-IP by name $haip = $api->haip()->getByName('haip-name'); // Find HA-IPs by description $matchingHaips = $api->haip()->findByDescription('Load balancer'); // Order a new HA-IP $api->haip()->order('haip-loadbalancer', 'Web load balancer'); // Update HA-IP $haip = $api->haip()->getByName('haip-name'); $haip->setDescription('Updated description'); $api->haip()->update($haip); // Manage port configurations $portConfigs = $api->haipPortConfigurations()->getByHaipName('haip-name'); // Get HA-IP status reports $statusReports = $api->haipStatusReports()->getByHaipName('haip-name'); // Manage HA-IP certificates $certificates = $api->haipCertificates()->getByHaipName('haip-name'); // Cancel HA-IP $api->haip()->cancel('haip-name', 'end'); ``` -------------------------------- ### Handle API Rate Limiting - PHP Source: https://context7.com/transip/transip-api-php/llms.txt Demonstrates how to retrieve and interpret API rate limit information (limit, remaining requests, reset time) after an API call. Includes a function to automatically wait if rate limits are exceeded. Requires the TransIP API client. ```php domains()->getAll(); // Check rate limit status after the call $limit = $api->getRateLimitLimit(); // Maximum requests allowed $remaining = $api->getRateLimitRemaining(); // Requests remaining $reset = $api->getRateLimitReset(); // Unix timestamp when limit resets echo "Rate limit: $remaining / $limit remaining\n"; echo "Resets at: " . date('Y-m-d H:i:s', $reset) . "\n"; // Example rate limit handling function makeApiCallWithRateLimitHandling($api, callable $apiCall) { $remaining = $api->getRateLimitRemaining(); if ($remaining <= 0) { $resetTime = $api->getRateLimitReset(); $waitSeconds = $resetTime - time() + 1; if ($waitSeconds > 0) { echo "Rate limited. Waiting $waitSeconds seconds...\n"; sleep($waitSeconds); } } return $apiCall(); } $result = makeApiCallWithRateLimitHandling($api, function() use ($api) { return $api->domains()->getAll(); }); ``` -------------------------------- ### Manage Email Mailboxes and Forwards with PHP Source: https://context7.com/transip/transip-api-php/llms.txt This snippet shows how to manage email mailboxes and forwards for a domain using the TransIP API. It covers retrieving, creating, updating, and deleting mailboxes, as well as managing mail forwards and lists. No external dependencies are required beyond the TransIP API client library. ```php mailboxes()->getByDomainName($domainName); foreach ($mailboxes as $mailbox) { echo "Mailbox: " . $mailbox->getIdentifier() . "\n"; echo " Local part: " . $mailbox->getLocalPart() . "\n"; echo " Max disk: " . $mailbox->getMaxDiskUsage() . " MB\n"; echo " Used: " . $mailbox->getCurrentDiskUsage() . " MB\n"; } // Get specific mailbox $mailbox = $api->mailboxes()->getByDomainNameAndIdentifier($domainName, 'mailbox-identifier'); // Create a new mailbox $api->mailboxes()->create( 'example.com', // Domain name 'info', // Local part (info@example.com) 1024, // Max disk usage in MB 'SecureP@ssw0rd!', // Password '' // Forward to address (optional) ); // Update mailbox $api->mailboxes()->update( 'mailbox-identifier', 'example.com', 2048, // New max disk usage 'NewP@ssw0rd!', // New password 'backup@example.com' // Forward copy to this address ); // Update specific fields only $api->mailboxes()->updateField( 'mailbox-identifier', 'example.com', null, // Keep current disk usage 'OnlyPassword!', // Update password only null // Keep current forward ); // Delete mailbox $api->mailboxes()->delete('mailbox-identifier', 'example.com'); // Manage mail forwards $forwards = $api->mailForwards()->getByDomainName('example.com'); // Manage mail lists $lists = $api->mailLists()->getByDomainName('example.com'); ``` -------------------------------- ### PUT /vps/firewall Source: https://context7.com/transip/transip-api-php/llms.txt Configure and update firewall rules for specific VPS instances to control inbound traffic. ```APIDOC ## PUT /vps/{vpsName}/firewall ### Description Update the firewall ruleset for a specific VPS instance. ### Method PUT ### Endpoint /vps/{vpsName}/firewall ### Parameters #### Path Parameters - **vpsName** (string) - Required - The name of the VPS ### Request Body - **ruleSet** (array) - Required - List of firewall rules (description, startPort, endPort, protocol, whitelist) ### Response #### Success Response (200) - **message** (string) - Confirmation of firewall update ### Response Example { "message": "Firewall updated successfully" } ``` -------------------------------- ### Include Composer Autoloader in PHP Source: https://github.com/transip/transip-api-php/blob/master/README.md This code demonstrates how to include Composer's autoloader in your PHP project to make the TransIP API library classes available. This is a standard practice when using libraries managed by Composer. ```php require_once('vendor/autoload.php'); ``` -------------------------------- ### Authenticate with TransIP API using PHP Source: https://github.com/transip/transip-api-php/blob/master/README.md This PHP code snippet illustrates how to authenticate with the TransIP RestAPI using the TransIP API Library. It requires your TransIP login name, a private key, and an option to generate tokens for whitelisted IPs. It then creates a test connection to verify the authentication. ```php use Transip\Api\Library\TransipAPI; require_once(__DIR__ . '/vendor/autoload.php'); // Your login name on the TransIP website. $login = ''; // If the generated token should only be usable by whitelisted IP addresses in your Controlpanel $generateWhitelistOnlyTokens = true; // One of your private keys; these can be requested via your Controlpanel $privateKey = ''; $api = new TransipAPI( $login, $privateKey, $generateWhitelistOnlyTokens ); // Create a test connection to the api $response = $api->test()->test(); if ($response === true) { echo 'API connection successful!'; } ``` -------------------------------- ### Manage DNS Records with PHP Source: https://context7.com/transip/transip-api-php/llms.txt Provides methods to retrieve, add, update, and remove DNS records for a domain. Supports various record types including A, AAAA, CNAME, MX, and TXT. ```php domainDns()->getByDomainName('example.com'); foreach ($dnsEntries as $entry) { echo sprintf( "%s %d IN %s %s\n", $entry->getName(), $entry->getExpire(), $entry->getType(), $entry->getContent() ); } // Add a new DNS entry $newEntry = new DnsEntry(); $newEntry->setName('api'); $newEntry->setExpire(300); $newEntry->setType('A'); $newEntry->setContent('37.97.254.1'); $api->domainDns()->addDnsEntryToDomain('example.com', $newEntry); // Update an existing DNS entry $updatedEntry = new DnsEntry(); $updatedEntry->setName('api'); $updatedEntry->setExpire(3600); $updatedEntry->setType('A'); $updatedEntry->setContent('37.97.254.2'); $api->domainDns()->updateEntry('example.com', $updatedEntry); // Replace all DNS entries at once $allEntries = [ new DnsEntry(['name' => '@', 'expire' => 300, 'type' => 'A', 'content' => '37.97.254.1']), new DnsEntry(['name' => 'www', 'expire' => 300, 'type' => 'CNAME', 'content' => '@']), new DnsEntry(['name' => '@', 'expire' => 3600, 'type' => 'MX', 'content' => '10 mail.example.com.']), new DnsEntry(['name' => '@', 'expire' => 3600, 'type' => 'TXT', 'content' => 'v=spf1 include:_spf.transip.email ~all']), ]; $api->domainDns()->update('example.com', $allEntries); // Remove a DNS entry $entryToRemove = new DnsEntry(); $entryToRemove->setName('old-subdomain'); $entryToRemove->setExpire(300); $entryToRemove->setType('A'); $entryToRemove->setContent('37.97.254.1'); $api->domainDns()->removeDnsEntry('example.com', $entryToRemove); ``` -------------------------------- ### Manage Domains via TransIP API Source: https://context7.com/transip/transip-api-php/llms.txt Retrieve and filter domain information using the domain repository. Supports fetching all domains, paginated results, specific domains by name, and filtering by tags. ```php domains()->getAll(); foreach ($domains as $domain) { echo "Domain: " . $domain->getName() . "\n"; } $includes = ['nameservers', 'contacts']; $domainsWithDetails = $api->domains()->getAll($includes); $page = 1; $itemsPerPage = 25; $paginatedDomains = $api->domains()->getSelection($page, $itemsPerPage, $includes); $domain = $api->domains()->getByName('example.com', $includes); $taggedDomains = $api->domains()->getByTagNames(['production', 'api']); ``` -------------------------------- ### Update DNS Record using TransIP API PHP Source: https://github.com/transip/transip-api-php/blob/master/README.md This PHP code snippet demonstrates how to update a specific DNS record for a domain using the TransIP API Library. It involves creating a `DnsEntry` object with the new details and then calling the `updateEntry` method on the `domainDns` service. ```php $homeIpAddress = '37.97.254.1'; $dnsEntry = new \Transip\Api\Library\Entity\Domain\DnsEntry(); $dnsEntry->setName('homeip'); // subdomain $dnsEntry->setExpire(300); $dnsEntry->setType('A'); $dnsEntry->setContent($homeIpAddress); $api->domainDns()->updateEntry('example.com', $dnsEntry); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.