C#

SDK for bunny.net 🐰

NuGet Version

Installation

dotnet add package BunnyLauncher.BunnySdk

Prerequisites

  • Please read the authentication guide to learn more about where to find your AccessKey and which AccessKey should be used for each client.
  • Please read the limitations guide to learn more about known limitations and bugs, such as nullable and optional typing.
  • Please read the supported endpoints guide to learn more about which endpoints are supported.

Quickstart

Create the client

using bunny_sdk;var client = BunnySdk.CreateBunnyApiClient(  new BunnySdk.CreateBunnyApiClientParameters  {    AccessKey = Environment.GetEnvironmentVariable("BUNNY_ACCESS_KEY") ?? "",  });

Call a simple endpoint

fetch countries

using bunny_sdk;var client = BunnySdk.CreateBunnyApiClient(  new BunnySdk.CreateBunnyApiClientParameters  {    AccessKey = Environment.GetEnvironmentVariable("BUNNY_ACCESS_KEY") ?? "",  });try{  var countries = await client.Country.GetAsync();}catch (Exception e){  Console.WriteLine(e);  throw;}

log countries

using bunny_sdk;var client = BunnySdk.CreateBunnyApiClient(  new BunnySdk.CreateBunnyApiClientParameters  {    AccessKey = Environment.GetEnvironmentVariable("BUNNY_ACCESS_KEY") ?? "",  });try{  var countries = await client.Country.GetAsync();  if (countries != null)  {    for (int i = 0; i < countries.Count; i++)    {      Console.WriteLine($"{i}: {countries[i].Name}");    }  }}catch (Exception e){  Console.WriteLine(e);  throw;}

Call a complex endpoint

The List Storage Zones endpoint is a more complex example that has required parameters.

fetch storage zones

using bunny_sdk;var client = BunnySdk.CreateBunnyApiClient(  new BunnySdk.CreateBunnyApiClientParameters  {    AccessKey = Environment.GetEnvironmentVariable("BUNNY_ACCESS_KEY") ?? "",  });try{  var storagezoneGetResponse = await client.Storagezone.GetAsync(    request =>    {      request.QueryParameters.IncludeDeleted = true;      request.QueryParameters.Page = 1;      request.QueryParameters.PerPage = 1000;    }  );}catch (Exception e){  Console.WriteLine(e);  throw;}

log storage zones

using bunny_sdk;var client = BunnySdk.CreateBunnyApiClient(  new BunnySdk.CreateBunnyApiClientParameters  {    AccessKey = Environment.GetEnvironmentVariable("BUNNY_ACCESS_KEY") ?? "",  });try{  var storagezoneGetResponse = await client.Storagezone.GetAsync(    request =>    {      request.QueryParameters.IncludeDeleted = true;      request.QueryParameters.Page = 1;      request.QueryParameters.PerPage = 1000;    }  );  if (storagezoneGetResponse != null && storagezoneGetResponse.Items != null)  {    var storageZones = storagezoneGetResponse.Items;    for (int i = 0; i < storageZones.Count; i++)    {      Console.WriteLine($"{i}: {storageZones[i].Name}");    }  }}catch (Exception e){  Console.WriteLine(e);  throw;}

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.

C# classes

The using directive imports all the types from that namespace.