duffelhq / duffel-api-dotnet

DotNet client library for the Duffel API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

DotNet client library for the Duffel API

License:MIT License


Languages

Language:C# 100.0%