PHP
SDK for bunny.net 🐰
Installation
composer require bunny-launcher/bunny-sdk
Prerequisites
- Please read the authentication guide to learn more about where to find your AccessKeyand whichAccessKeyshould be used for each client.
- Please read the limitations guide to learn more about known limitations and bugs, such as nullableandoptionaltyping.
- Please read the supported endpoints guide to learn more about which endpoints are supported.
Quickstart
Create the client
<?phpuse BunnyLauncher\BunnySdk;require_once __DIR__ . '/../vendor/autoload.php';$client = BunnySdk::createBunnyApiClient(accessKey: $_ENV["BUNNY_ACCESS_KEY"]);
Call a simple endpoint
fetch countries
<?phpuse BunnyLauncher\BunnySdk;use Microsoft\Kiota\Abstractions\ApiException; require_once __DIR__ . '/../vendor/autoload.php';$client = BunnySdk::createBunnyApiClient(accessKey: $_ENV["BUNNY_ACCESS_KEY"]);try {  $countries = $client->country()->get()->wait();} catch (ApiException $exception) {  echo $exception->getMessage();  throw $exception;}
log countries
<?phpuse BunnyLauncher\BunnySdk;use Microsoft\Kiota\Abstractions\ApiException;require_once __DIR__ . '/../vendor/autoload.php';$client = BunnySdk::createBunnyApiClient(accessKey: $_ENV["BUNNY_ACCESS_KEY"]);try {  $countries = $client->country()->get()->wait();  if ($countries) {    for ($i = 0, $size = count($countries); $i < $size; ++$i) {      echo "{$i}: {$countries[$i]->getName()}\n";    }  }} catch (ApiException $exception) {  echo $exception->getMessage();  throw $exception;}
Call a complex endpoint
The List Storage Zones endpoint is a more complex example that has required parameters.
fetch storage zones
<?phpuse BunnyLauncher\BunnySdk;use BunnyApiClient\Storagezone\StoragezoneRequestBuilderGetRequestConfiguration;use BunnyApiClient\Storagezone\StoragezoneRequestBuilderGetQueryParameters;use Microsoft\Kiota\Abstractions\ApiException;require_once __DIR__ . '/../vendor/autoload.php';$client = BunnySdk::createBunnyApiClient(accessKey: $_ENV["BUNNY_ACCESS_KEY"]);try {  $storageZonesResponse = $client->storagezone()->get(    new StoragezoneRequestBuilderGetRequestConfiguration(      queryParameters: new StoragezoneRequestBuilderGetQueryParameters(        includeDeleted: true,        page: 1,        perPage: 1000,      ),    ),  )->wait();} catch (ApiException $exception) {  echo $exception->getMessage();  throw $exception;}
log storage zones
<?phpuse BunnyLauncher\BunnySdk;use BunnyApiClient\Storagezone\StoragezoneRequestBuilderGetRequestConfiguration;use BunnyApiClient\Storagezone\StoragezoneRequestBuilderGetQueryParameters;use Microsoft\Kiota\Abstractions\ApiException;require_once __DIR__ . '/../vendor/autoload.php';$client = BunnySdk::createBunnyApiClient(accessKey: $_ENV["BUNNY_ACCESS_KEY"]);try {  $storageZonesResponse = $client->storagezone()->get(    new StoragezoneRequestBuilderGetRequestConfiguration(      queryParameters: new StoragezoneRequestBuilderGetQueryParameters(        includeDeleted: true,        page: 1,        perPage: 1000,      ),    ),  )->wait();  if ($storageZonesResponse) {    $storageZones = $storageZonesResponse->getItems();    for ($i = 0, $size = count($storageZones); $i < $size; ++$i) {      echo "{$i}: {$storageZones[$i]->getName()}\n";    }  }} catch (ApiException $exception) {  echo $exception->getMessage();  throw $exception;}
All required parameters from the documentation are also required in the Bunny SDK. In this example, the required parameters are:
- includeDeleted
- page
- perPage
Despite the documentation setting the default page parameter to 0, the default value fails the validation, where the minimum page is 1.
If you receive a 400 Bad Request error, please double-check your parameters.
PHP classes
Most model and enum classes are found in:
- <client>\<group>\<class>.
- <client>\Models\<group>\<class>.
use BunnyApiClient\Storagezone\StoragezoneRequestBuilderGetQueryParameters;use BunnyApiClient\Models\StorageZone\StorageZone;