Skip to main content

PHP Client

We maintain a PHP client here.

Version constraints

  • v1.x supports PHP 5.6
  • v2.x supports PHP 7.4

From version 3, we switched to an OpenAPI based generator.

Versions 3 and up require a minimum of PHP 8.1 and follow semantic versioning.

Please refer to composer.json for any specific language requirements for your version.

Note that older versions of the client may not have all the same endpoints supported.

Installation

You can install the package via Composer:

composer require krystal/katapult

Usage

It will use PSR HTTP discovery to locate an imlpementation of the PSR ClientInterface.

If you need control over this, you can call setHttpClient in ClientFactory.

The usage sample below emits the IPv4 and IPv6 addresses for each VM in your Organization.

use KatapultAPI\Core\ClientFactory;

// Get the API token from a dotenv or wherever you like
$katapultAPIClientFactory = new ClientFactory('your-katapult-api-token');

// create() makes use of Psr18ClientDiscovery and Psr17FactoryDiscovery
$katapultAPIClient = $katapultAPIClientFactory->create();

$virtualMachines = $katapultAPIClient->getOrganizationVirtualMachines([
'organization[id]' => 'your-katapult-organization-id',
])->getVirtualMachines();

foreach ($virtualMachines as $virtualMachine) {
echo $virtualMachine->getHostname() . PHP_EOL;
foreach ($virtualMachine->getIpAddresses() as $ipAddress) {
$prefix = filter_var($ipAddress->getAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? 'ipv4' : 'ipv6';
echo ' ' . $prefix . ': ' . $ipAddress->getAddress() . PHP_EOL;
}
}

Output

example
ipv4: 93.184.216.34
ipv6: 2606:2800:220:1:248:1893:25c8:1946