A (minimalistic) wrapper for Travelpayouts (JetRadar/Aviasales).
The following APIs are supported.
-
Data Access API
-
Flight Search API
-
Affiliate Statistics API
See also: a module for working with Travelpayouts data files: travelpayouts-data.
Table of Contents
- Install
- Use
- API
- travelpayoutsAPI([options])
- All methods
- Prices
- prices.latest(options, callback)
- prices.monthMatrix(options, callback)
- prices.weekMatrix(options, callback)
- prices.nearestPlacesMatrix(options, callback)
- prices.cheap(options, callback)
- prices.monthly(options, callback)
- prices.direct(options, callback)
- prices.calendar(options, callback)
- prices.holidaysByRoutes(options, callback)
- minPricesCalendar(options, callback)
- specialOffers(callback)
- Flight Search
- Affiliate statistics
- Price map
- Directions
- Misc
- Example
- Tests
- License
npm i travelpayouts
- Sign up for Travelpayouts.
- Obtain an API token in the section Developers → API.
- Include the library in your code and pass the token:
var travelpayoutsAPI = require('travelpayouts');
var tapi = travelpayoutsAPI({ token: 'your_token' });
You can now use API methods.
Returns API object, accepts the following params:
-
token
— an API token. Required if you are going to use restricted APIs. -
marker
— your unique affiliate identifier. Required for Flight Search API. -
host
— your website host or app name. Required for Flight Search API. -
requestOptions
— request options, which will be used by default. Use it to specify a proxy, timeout, etc.
All methods accept an object with params as the first argument. All methods accept callback, that will be called with results of request. The first argument to callback will be an error or null
if no errors occured.
For each method listed below there is a link to the relevant section of the official documentation.
Please note, that API token, marker, and host always passed to the API automatically, and you don't have to specify it for each request manually.
Allows to access various cache data from flight searches.
Attention, the data is transferred from the cache, so it is recommended to use it to generate static pages.
Prices for the latest 48 hours
Prices for each day of the month, grouped by number of stops
Cheapest tickets grouped by month
The API returns an XML, however the module returns a ready to use JS object.
Please note, that md5 signature is generated automatically by this module, so you don't need to do it in your code.
Getting a link to the agency website
You don't need to specify callback
param in options since the module does this automatically.
Currency exchange rate related to Russian Ruble (in Russian)
var travelpayoutsAPI = require('travelpayouts');
var tapi = travelpayoutsAPI({ token: 'your_token' });
tapi.prices.latest({
currency: 'rub',
period_type: 'year',
page: 1,
limit: 30,
show_to_affiliates: true,
sorting: 'price',
trip_class: 0
}, function (err, result) {
if (err) throw err;
console.log(result);
});
In order to run the tests clone the repo, run npm install
inside it and run npm test
. This runs the tests on a test data.
You can also run the tests against the actual API to test library compatibility. Use the command:
mocha --reporter=spec -t 10000 -s 10000 tests/test.api.js --token your_token
The MIT License (MIT)
Copyright (c) 2016 Alexey Komarov alex7kom@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.