Amadeus Node SDK
Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more.
For more details see the Node
documentation on
Amadeus.com.
Installation
This module has been tested using Node 6 and higher, though it should work with
Node 4 and 5 as well. You can install install it using Yarn or NPM.
npm install amadeus --save
Getting Started
To make your first API call you will need to register for an Amadeus Developer
Account and set up your first
application.
var Amadeus = require('amadeus');
var amadeus = new Amadeus({
clientId: 'REPLACE_BY_YOUR_API_KEY',
clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
});
amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'SYD',
destinationLocationCode: 'BKK',
departureDate: '2020-08-01',
adults: '2'
}).then(function(response){
console.log(response.data);
}).catch(function(responseError){
console.log(responseError.code);
});
Initialization
The client can be initialized directly.
var amadeus = new Amadeus({
clientId: 'REPLACE_BY_YOUR_API_KEY',
clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
});
Alternatively it can be initialized without any parameters if the environment
variables AMADEUS_CLIENT_ID
and AMADEUS_CLIENT_SECRET
are present.
var amadeus = new Amadeus();
Your credentials can be found on the Amadeus
dashboard. Sign
up for an account today.
By default the environment for the SDK is the test
environment. To switch to
a production (paid-for) environment please switch the hostname as follows:
var amadeus = new Amadeus({
hostname: 'production'
});
Documentation
Amadeus has a large set of APIs, and our documentation is here to get you
started today. Head over to our
Reference documentation for
in-depth information about every SDK method, it's arguments and return types.
Making API calls
This library conveniently maps every API path to a similar path.
For example, GET /v2/reference-data/urls/checkin-links?airlineCode=BA
would be:
amadeus.referenceData.urls.checkinLinks.get({ airlineCode: 'BA' });
Similarly, to select a resource by ID, you can pass in the ID to the singular path.
For example, GET /v1/shopping/hotelOffer/123/
would be:
amadeus.shopping.hotelOffer('123').get(...);
You can make any arbitrary API call as well directly with the .client.get
method:
amadeus.client.get('/v2/reference-data/urls/checkin-links', { airlineCode: 'BA' });
Or with a POST
using .client.post
method:
amadeus.client.post('/v1/shopping/flight-offers/pricing', JSON.stringify({ data }));
Promises
Every API call returns a Promise
that either resolves or rejects. Every
resolved API call returns a Response
object containing a body
attribute
with the raw response. If the API call contained a JSON response it will parse
the JSON into the .result
attribute. If this data also contains a data
key,
it will make that available as the .data
attribute.
For a failed API call it returns a ResponseError
containing the (parsed or unparsed) response, the request, and an error code.
amadeus.referenceData.urls.checkinLinks.get({
airlineCode: 'BA'
}).then(function(response){
console.log(response.body);
console.log(response.result);
console.log(response.data);
}).catch(function(error){
console.log(error.response);
console.log(error.response.request);
console.log(error.code);
});
If an API endpoint supports pagination, the other pages are available under the
.next
, .previous
, .last
and .first
methods.
amadeus.referenceData.locations.get({
keyword: 'LON',
subType: 'AIRPORT,CITY'
}).then(function(response){
console.log(response.data);
return amadeus.next(response);
}).then(function(nextResponse){
console.log(nextResponse.data);
});
If a page is not available, the response will resolve to null
.
Logging & Debugging
The SDK makes it easy to add your own logger compatible with the default console
.
var amadeus = new Amadeus({
clientId: 'REPLACE_BY_YOUR_API_KEY',
clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
logger: new MyConsole()
});
Additionally, to enable more verbose logging, you can set the appropriate level
on your own logger, though the easiest way would be to enable debugging via a
parameter on initialization, or using the AMADEUS_LOG_LEVEL
environment
variable. The available options are silent
(default), warn
, and debug
.
var amadeus = new Amadeus({
clientId: 'REPLACE_BY_YOUR_API_KEY',
clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
logLevel: 'debug'
});
List of supported endpoints
amadeus.shopping.flightDestinations.get({
origin : 'MAD'
})
amadeus.shopping.flightDates.get({
origin : 'MAD',
destination : 'MUC'
})
amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'SYD',
destinationLocationCode: 'BKK',
departureDate: '2020-08-01',
adults: '2'
})
amadeus.shopping.flightOffers.get({
origin: 'MAD',
destination: 'NYC',
departureDate: '2020-08-01'
}).then(function(response){
return amadeus.shopping.flightOffers.prediction.post(
JSON.stringify(response.result)
);
}).then(function(response){
console.log(response.data);
}).catch(function(responseError){
console.log(responseError);
});
amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'SYD',
destinationLocationCode: 'BKK',
departureDate: '2020-08-01',
adults: '1'
}).then(function(response){
return amadeus.booking.flightOrders.post(
JSON.stringify({
'type': 'flight-order',
'flightOffers': response.flightOffers,
'travelers_info': []
})
);
}).then(function(response){
console.log(response.data);
}).catch(function(responseError){
console.log(responseError);
});
amadeus.shopping.flightOffers.get({
origin: 'MAD',
destination: 'NYC',
departureDate: '2020-08-01'
}).then(function(response){
return amadeus.shopping.flightOffers.pricing.post(
JSON.stringify({
'data': {
'type': 'flight-offers-pricing',
'flightOffers': response.data
}
})
)
}).then(function(response){
console.log(response.data);
}).catch(function(responseError){
console.log(responseError);
});
amadeus.shopping.flightOffers.get({
origin: 'MAD',
destination: 'NYC',
departureDate: '2020-08-01'
}).then(function(response){
return amadeus.shopping.seatmaps.post(
JSON.stringify({
'data': response.data
})
);
}).then(function(response){
console.log(response.data);
}).catch(function(responseError){
console.log(responseError);
});
amadeus.shopping.seatmaps.get({
'flight-orderId': 'XXX'
});
amadeus.referenceData.urls.checkinLinks.get({
airlineCode : 'BA'
})
amadeus.referenceData.airlines.get({
airlineCodes : 'U2'
})
amadeus.referenceData.locations.get({
keyword : 'LON',
subType : Amadeus.location.any
})
amadeus.referenceData.location('ALHR').get()
amadeus.referenceData.locations.airports.get({
longitude : 0.1278,
latitude : 51.5074
})
amadeus.travel.analytics.airTraffic.booked.get({
originCityCode : 'MAD',
period : '2017-08'
})
amadeus.travel.analytics.airTraffic.traveled.get({
originCityCode : 'MAD',
period : '2017-01'
})
amadeus.travel.analytics.airTraffic.busiestPeriod.get({
cityCode: 'MAD',
period: '2017',
direction: Amadeus.direction.arriving
})
amadeus.travel.tripParserJobs().post(
JSON.stringify({
'type': 'trip-parser-job',
'content': 'base64String'
})
)
amadeus.travel.tripParserJobs('XXX').get()
amadeus.travel.tripParserJobs('XXX').result.get()
amadeus.shopping.hotelOffers.get({
cityCode : 'MAD'
})
amadeus.shopping.hotelOffersByHotel.get({
hotelId : 'XKPARC12'
})
amadeus.shopping.hotelOffer('XXX').get()
amadeus.booking.flightOrder('XXX').get()
amadeus.booking.flightOrder('XXX').delete()
amadeus.booking.hotelBookings.post(
JSON.stringify({
'offerId': 'XXX',
'guests': [],
'payments': []
}
)
)
amadeus.referenceData.locations.pointsOfInterest.get({
latitude : 41.397158,
longitude : 2.160873
})
amadeus.referenceData.locations.pointsOfInterest.bySquare.get({
north: 41.397158,
west: 2.160873,
south: 41.394582,
east: 2.177181
})
amadeus.eReputation.hotelSentiments.get({
hotelIds: 'XKPARC12'
})
amadeus.travel.predictions.tripPurpose.get({
originLocationCode: 'NYC',
destinationLocationCode: 'MAD',
departureDate: '2020-08-01',
returnDate: '2020-08-12'
})
amadeus.media.files.generatedPhotos.get({
category: 'BEACH'
})
amadeus.travel.predictions.flightDelay.get({
originLocationCode: 'BRU',
destinationLocationCode: 'FRA',
departureDate: '2020-01-14',
departureTime: '11:05:00',
arrivalDate: '2020-01-14',
arrivalTime: '12:10:00',
aircraftCode: '32A',
carrierCode: 'LH',
flightNumber: '1009',
duration: 'PT1H05M'
})
amadeus.airport.predictions.onTime.get({
airportCode: 'JFK',
date: '2020-08-01'
})
Development & Contributing
Want to contribute? Read our Contributors Guide for
guidance on installing and running this code in a development environment.
License
This library is released under the MIT License.
Help
Our developer support team is here to
help you. You can find us on
StackOverflow and
email.
4.0.0 - 2020-03-25
Add support for the Flight Offers Price API
The Flight Offers Price API confirms the flight price (including taxes and fees) and availability for a given flight returned by the Flight Offers Search API. The API also returns pricing for ancillary products (additional bags, extra legroom, etc.) and the payment information details needed for booking.
Add support for the Flight Create Orders API
The Flight Create Orders API is a flight booking API that lets you perform the final booking for a desired flight and ancillary products (additional bags, extra legroom, etc.). The API returns a unique ID for the flight order and reservation details. This API is used to perform the final booking on confirmed fares returned by the Flight Offers Price API.
Add support for the Flight Order Management API
The Flight Order Management API lets you consult bookings created through the Flight Create Orders API. Using the booking ID generated by Flight Create Orders, Flight Order Management returns the last-updated version of the booking record with any post-booking modifications including but not limited to ticket information, form of payment or other remarks.
Add support for the Hotel Booking API
The Amadeus Hotel Booking API lets you complete bookings at over 150,000 hotels and accommodations around the world. To complete bookings, you must first use the Amadeus Hotel Search API to search for hotel deals, select the desired offer and confirm the final price and availability. You can then use the Hotel Booking API to complete the reservation by providing an offer id, guest information and payment information.
Add support for the SeatMap Display API
SeatMap Display API allows you to get information to display airplane cabin plan from a Flight Offer in order for the traveler to be able to choose his seat during the flight booking flow thanks to POST method. In addition GET method allows you to display airplane cabin plan from an existing Flight Order.
Remove support for Most Searched Destinations
Add support for the Trip Parser API
The Trip Parser API parses information from various booking confirmation emails and returns a standardized, structured travel itinerary. The API can extract relevant information from a wide variety of flight, hotel, rental car and rail providers’ confirmation emails by first identifying the provider and then using a database of provider-specific email structures to determine which information to extract. The API then returns a link to the JSON structure of the itinerary.