Duffel (Duffel v0.1.0)

Copy Markdown View Source

An Elixir client for the Duffel API.

Usage

Build a client, then pass it to resource functions:

client = Duffel.new(access_token: "duffel_test_...")

{:ok, offer_request} =
  Duffel.OfferRequests.create(client, %{
    slices: [%{origin: "LHR", destination: "JFK", departure_date: "2026-07-01"}],
    passengers: [%{type: "adult"}],
    cabin_class: "economy"
  })

Configuration

new/0 reads configuration from the application environment:

config :duffel, access_token: System.fetch_env!("DUFFEL_ACCESS_TOKEN")

Supported options (for new/1 and the application environment):

  • :access_token - Duffel API access token (required)
  • :base_url - defaults to "https://api.duffel.com"
  • :api_version - value for the Duffel-Version header, defaults to "v2"
  • :receive_timeout - milliseconds to wait for a response, defaults to 130_000, which covers the 120 seconds Duffel allows order and booking creation to take
  • :req_options - extra options merged into every Req request (useful for test stubs). Merged last, so it overrides everything above

Summary

Functions

Builds a client from the :duffel application environment.

Builds a client from the given options.

Functions

new()

@spec new() :: Duffel.Client.t()

Builds a client from the :duffel application environment.

See the module documentation for supported configuration keys.

new(opts)

@spec new(keyword()) :: Duffel.Client.t()

Builds a client from the given options.

Examples

iex> client = Duffel.new(access_token: "duffel_test_abc")
iex> client.api_version
"v2"