Warning
This client library is not currently being supported by Duffel due to a lack of adoption.
You're welcome to fork the repositories and continue maintaining them for your own use.
If, in the future, there's sufficient demand for a particular client library, we'll reconsider our decision to officially support it.
DotNet client library for the Duffel API
Installing latest version:
Install-Package Duffel.ApiClient
You first need to set the API token you can find in the Duffel dashboard under the section Developers > Access Tokens.
using Duffel.ApiClient;
var accessToken = Environment.GetEnvironmentVariable("DUFFEL_ACCESS_TOKEN");
var client = new DuffelApiClient(accessToken: accessToken);
After you have a client you can interact with, you can make calls to the Duffel API:
var response = await client.OfferRequests.Create(offersRequest, returnOffers: false);
var selectedOffer = response.Offers.First();
var pricedOffer = await client.Offers.Get(selectedOffer.Id, returnAvailableServices: true);
The call to API can result in an error, which will then throw one out of two exceptions:
try
{
var response = await client.OfferRequests.Create(offersRequest, returnOffers: false);
}
catch (ApiException apiEx)
{
// apiEx.Errors - list of errors returned by the the API
// apiEx.Metadata.RequestId - a Duffel id of the request
// apiEx.StatusCode - an Http status code returned by the API
}
catch (ApiDeserializationException desEx)
{
// desEx.Payload - contains payload returned by the API
// apiEx.StatusCode - an Http status code returned by the API
}
For more detailed information about error handling, see: https://duffel.com/docs/api/overview/errors
You can find a complete e2e examples in ./Examples folder
To publish a new version to Nuget, update the version in the csproj file and commit the change. Head over to releases page and create a new release with a new tag following SemVer e.g. 1.0.0-RC3.