Getting Started with Flights
Sign up for a Duffel account (it takes about 1 minute!)
On the navigation header, click on "More", then navigate to "Developers"
Create a test access token from the "Access tokens" page in your Dashboard
curl
in your terminal, or you can script the flow using your preferred programming language, or you can use the API in an HTTP client like Postman.Tip
Overview
Searching for flights
Selecting an offer from the search results
Creating a booking using the selected offer
Searching for flights
JavaScript
duffel.offerRequests.create({slices : [{origin: "NYC",destination: "ATL",departure_date: "2021-06-21"},{origin: "ATL",destination: "NYC",departure_date: "2021-07-21"}],passengers: [{ type: "adult" }, { type: "adult" }, { age: 1 }],cabin_class: "business",})
What is a slice?
ATL
for Atlanta's Hartsfield-Jackson International Airport) or for a city (for example NYC
for New York City, which covers multiple airports).How do passengers work in the API?
type
: adult
.What will I get back?
id
for the offer request. You may use this ID to retrieve the offer request later.offers
.slices
and passengers
.passengers
. Each is given an id
, which we'll need to refer to later, when making a booking.Learn more
Return all offers in the offer request allows your application to pre-process the data. This is the example above. You can find the API documentation here
Streaming batches of offers is a good choice when you want to to start processing and or displaying the offers as soon as they're available. You can find the API documentation here
Selecting an offer from the search results
id
with the "Get a single offer" endpoint:JavaScript
duffel.offers.get(OFFER_ID)
$OFFER_ID
with the ID of one of the offers returned.total_currency
and total_amount
attributes.Slices and segments
JFK
) and has a stop in Washington Dulles Airport (IAD
) on the way to ATL
, and then no stops on the way back to JFK
. On the outbound slice, you'll have 2 segments: one with JFK
as its origin and IAD
as its destination, and a second one from IAD
to ATL
. As the second slice is a direct flight with no stops, there's just a single segment from ATL
back to JFK
.Learn more
Creating a booking using the selected offer
The ID of the offer you'd like to book
Basic necessary information about the passengers
Payment method and information to confirm the order
JavaScript
duffel.orders.create({selected_offers: [OFFER_ID],payments: [{type: "balance",currency: TOTAL_CURRENCY,amount: TOTAL_AMOUNT}],passengers: [{phone_number: "+442080160508",email: "tony@example.com",born_on: "1980-07-24",title: "mr",gender: "m",family_name: "Stark",given_name: "Tony",infant_passenger_id: INFANT_PASSENGER_ID,id: ADULT_PASSENGER_ID_1},{phone_number: "+442080160509",email: "potts@example.com",born_on: "1983-11-02",title: "mrs",gender: "m",family_name: "Potts",given_name: "Pepper",id: ADULT_PASSENGER_ID_2},{phone_number: "+442080160506",email: "morgan@example.com",born_on: "2019-08-24",title: "mrs",gender: "f",family_name: "Stark",given_name: "Morgan",id: INFANT_PASSENGER_ID}]})
Selected offers
$OFFER_ID
with the one for the offer you'd like to book.Payments
type
:arc_bsp_cash
if you are a registered IATA travel agent and you are using your own airline relationships with Duffel.balance
if you are using Managed Content. Follow the "Collecting Customer Card Payments" guide if you want to collect the payment directly from your customer's card and use it here.
$TOTAL_CURRENCY
) in ISO 4217 format — it should match the offer's total_currency
— and the total amount ($TOTAL_AMOUNT
) of the order, which should match the offer's total_amount
.Passengers
id
from our Offer Request. To do this, simply replace the $ADULT_PASSENGER_ID_1
, $ADULT_PASSENGER_ID_2
and $INFANT_PASSENGER_ID
from the example above.id
to the responsible adult's infant_passenger_id
. All infants must have unique responsible adults.Learn more
Keep Learning
booking_reference
, which you'd use to find the booking on the airline's website. The order can be retrieved any time by its id
.