MIT License

项目介绍

amadeus4dev/amadeus-node 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 MIT License 许可证,目前获得 227 个 Star、79 次 Fork。

仓库全名
amadeus4dev/amadeus-node
开源许可证
MIT License
Star 数
227
Fork 数
79
未关闭 Issue
8

README 摘要

Amadeus Node SDK Amadeus provides a rich set of APIs for the travel industry. For more details, check out the Amadeus for Developers Portal or the SDK class reference. Installation This module has been tested using Node LTS versions. You can install it using Yarn or NPM. Getting Started To make your first API call, you will need to register for an Amadeus Developer Account and set up your first application. Examples…

完整内容见 GitHub 原始 README 或本页 。

常见问题

amadeus-node 用什么语言开发?

主要使用 JavaScript 编写,采用 MIT License 许可证,目前有 227 个 Star。

amadeus-node 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 amadeus-node 的源码?

可以直接克隆仓库:git clone https://github.com/amadeus4dev/amadeus-node.git,默认分支为 master;安装与运行步骤见仓库 README。

amadeus-node 最近还在维护吗?

仓库最近一次更新为 2025年2月19日,当前有 8 个未关闭 Issue;Star 数为 227,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Node library for the Amadeus Self-Service travel APIs

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
402
价值分
161
活跃状态
归档

语言占比

JavaScript

Release

README

Amadeus Node SDK

Module Version Build and Deploy Maintainability Dependencies Discord

Amadeus provides a rich set of APIs for the travel industry. For more details, check out the Amadeus for Developers Portal or the SDK class reference.

Installation

This module has been tested using Node LTS versions. You can 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.

const Amadeus = require('amadeus');

const amadeus = new Amadeus({
  clientId: 'REPLACE_BY_YOUR_API_KEY',
  clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
});

amadeus.shopping.flightOffersSearch.get({
    originLocationCode: 'SYD',
    destinationLocationCode: 'BKK',
    departureDate: '2022-06-01',
    adults: '2'
}).then(function(response){
  console.log(response.data);
}).catch(function(responseError){
  console.log(responseError.code);
});

Examples

You can find all the endpoints in self-contained code examples.

Initialization

The client can be initialized directly.

// Initialize using parameters
const 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.

const amadeus = new Amadeus();

Your credentials can be found on the Amadeus dashboard.

By default, the SDK environment is set to test environment. To switch to a production (pay-as-you-go) environment, please switch the hostname as follows:

const 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, its 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/hotelOffers/123/ would be:

amadeus.shopping.hotelOffer('123').get(...);

You can make any arbitrary GET API call directly with the .client.get method as well:

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', { 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 contains a data key, that will be made available in data attribute.

For a failed API call, it returns a ResponseErrorobject 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);   //=> The raw body
  console.log(response.result); //=> The fully parsed result
  console.log(response.data);   //=> The data attribute taken from the result
}).catch(function(error){
  console.log(error.response); //=> The response object with (un)parsed data
  console.log(error.response.request); //=> The details of the request made
  console.log(error.code); //=> A unique error code to identify the type of error
});

Pagination

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); // first page
  return amadeus.next(response);
}).then(function(nextResponse){
  console.log(nextResponse.data); // second page
});

If a page is not available, the response will resolve to null.

Logging & Debugging

The SDK makes it easy to add your own logger that is compatible with the default console.

const 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. The easiest way would be to enable debugging via a parameter during initialization, or using the AMADEUS_LOG_LEVEL environment variable. The available options are silent (default), warn, and debug.

const amadeus = new Amadeus({
  clientId: 'REPLACE_BY_YOUR_API_KEY',
  clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
  logLevel: 'debug'
});

List of supported endpoints

//Airport Routes 
amadeus.airport.directDestinations.get({
     departureAirportCode: 'CDG',
})

//Airline Routes
//find all destinations served by a given airline
amadeus.airline.destinations.get({
     airlineCode: 'BA',
 })

// Flight Inspiration Search
amadeus.shopping.flightDestinations.get({
  origin : 'MAD'
})

// Flight Cheapest Date Search
amadeus.shopping.flightDates.get({
  origin : 'MAD',
  destination : 'MUC'
})

// Flight Offers Search GET
amadeus.shopping.flightOffersSearch.get({
  originLocationCode: 'SYD',
  destinationLocationCode: 'BKK',
  departureDate: '2022-11-01',
  adults: '2'
})

// Flight Offers Search POST
// A full example can be found at https://github.com/amadeus4dev/amadeus-code-examples
amadeus.shopping.flightOffersSearch.post(body)

// Flight Offers Price
amadeus.shopping.flightOffersSearch.get({
    originLocationCode: 'SYD',
    destinationLocationCode: 'BKK',
    departureDate: '2022-11-01',
    adults: '1'
}).then(function(response){
    return amadeus.shopping.flightOffers.pricing.post(
      {
        'data': {
          'type': 'flight-offers-pricing',
          'flightOffers': [response.data[0]]
        }
      }
    )
}).then(function(response){
    console.log(response.data);
}).catch(function(responseError){
    console.log(responseError);
});

// Flight Offers Price with additional parameters
// for example: check additional baggage options 
amadeus.shopping.flightOffers.pricing.post(body ,{include: 'bags'});

// Flight Create Orders
// To book the flight-offer(s) returned by the Flight Offers Price
// and create a flight-order with travelers' information.
// A full example can be found at https://git.io/JtnYo
amadeus.booking.flightOrders.post(
  {
    'type': 'flight-order',
    'flightOffers': [priced-offers],
    'travelers': []
  }
);

// Retrieve flight order with ID 'XXX'. This ID comes from the
// Flight Create Orders API, which is a temporary ID in test environment.
amadeus.booking.flightOrder('XXX').get()

// Cancel flight order with ID 'XXX'. This ID comes from the
// Flight Create Orders API, which is a temporary ID in test environment.
amadeus.booking.flightOrder('XXX').delete()

// Flight SeatMap Display
// To retrieve the seat map of each flight included
// in flight offers for MAD-NYC flight on 2021-08-01
amadeus.shopping.flightOffersSearch.get({
  originLocationCode: 'SYD',
  destinationLocationCode: 'BKK',
  departureDate: '2022-11-01',
  adults: '1'
}).then(function(response){
    return amadeus.shopping.seatmaps.post(
      {
        'data': [response.data[0]]
      }
    );
}).then(function(response){
    console.log(response.data);
}).catch(function(responseError){
    console.log(responseError);
});
// To retrieve the seat map for flight order with ID 'XXX'
amadeus.shopping.seatmaps.get({
  'flight-orderId': 'XXX'
});

// Flight Availabilities Search
amadeus.shopping.availability.flightAvailabilities.post(body);

// Branded Fares Upsell 
amadeus.shopping.flightOffers.upselling.post(body);

// Flight Choice Prediction
amadeus.shopping.flightOffersSearch.get({
    originLocationCode: 'SYD',
    destinationLocationCode: 'BKK',
    departureDate: '2022-11-01',
    adults: '2'
}).then(function(response){
    return amadeus.shopping.flightOffers.prediction.post(response);
}).then(function(response){
    console.log(response.data);
}).catch(function(responseError){
    console.log(responseError);
});

// Flight Checkin Links
amadeus.referenceData.urls.checkinLinks.get({
  airlineCode : 'BA'
})

// Airline Code Lookup
amadeus.referenceData.airlines.get({
  airlineCodes : 'U2'
})

// Airports and City Search (autocomplete)
// Find all the cities and airports starting by 'LON'
amadeus.referenceData.locations.get({
  keyword : 'LON',
  subType : Amadeus.location.any
})

// Get a specific city or airport based on its id
amadeus.referenceData.location('ALHR').get()

// Airport Nearest Relevant Airport (for London)
amadeus.referenceData.locations.airports.get({
  longitude : 0.1278,
  latitude  : 51.5074
})

// Flight Most Booked Destinations
amadeus.travel.analytics.airTraffic.booked.get({
  originCityCode : 'MAD',
  period : '2017-08'
}

// Flight Most Traveled Destinations
amadeus.travel.analytics.airTraffic.traveled.get({
  originCityCode : 'MAD',
  period : '2017-01'
})

// Flight Busiest Traveling Period
amadeus.travel.analytics.airTraffic.busiestPeriod.get({
  cityCode: 'MAD',
  period: '2017',
  direction: Amadeus.direction.arriving
})

// City Search API
// finds cities that match a specific word or string of letters. 
// Return a list of cities matching a keyword 'Paris'
amadeus.referenceData.locations.cities.get({
  keyword: 'Paris'
})

//Hotel Name Autocomplete API
//Autocomplete a hotel search field
amadeus.referenceData.locations.hotel.get({
     keyword: 'PARI',
     subType: 'HOTEL_GDS'
})

//Hotel List API 
//Get list of hotels by city code
amadeus.referenceData.locations.hotels.byCity.get({
      cityCode: 'PAR'
    })

//Get List of hot

提示:代码过长已自动截断

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

You can find us on StackOverflow or join our developer community on Discord.

评论

暂无评论