Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Latest commit

 

History

History
73 lines (54 loc) · 2.75 KB

README.md

File metadata and controls

73 lines (54 loc) · 2.75 KB

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.


GitHub license Nuget

duffel-api-dotnet

DotNet client library for the Duffel API

Getting started

Installing latest version:

Install-Package Duffel.ApiClient

Usage

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);

Error handling

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

Examples

You can find a complete e2e examples in ./Examples folder

Releasing a new package version

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.