Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Latest commit

 

History

History
278 lines (176 loc) · 10.1 KB

README-en.md

File metadata and controls

278 lines (176 loc) · 10.1 KB

Travelpayouts (JetRadar/Aviasales) API for Node.js

Build Status David

На русском

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

npm i travelpayouts

Use

  1. Sign up for Travelpayouts.
  2. Obtain an API token in the section Developers → API.
  3. 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.

API

travelpayoutsAPI([options])

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.

  • requestOptionsrequest options, which will be used by default. Use it to specify a proxy, timeout, etc.

All methods

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.

Prices

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.latest(options, callback)

Prices for the latest 48 hours

prices.monthMatrix(options, callback)

Prices for each day of the month, grouped by number of stops

prices.weekMatrix(options, callback)

Price calendar on week

prices.nearestPlacesMatrix(options, callback)

Prices for alternative routes

prices.cheap(options, callback)

Cheapest tickets

prices.monthly(options, callback)

Cheapest tickets grouped by month

prices.direct(options, callback)

Non-stop tickets

prices.calendar(options, callback)

Tickets for each day of month

prices.holidaysByRoutes(options, callback)

Cheap flights for holidays

minPricesCalendar(options, callback)

Price calendar

specialOffers(callback)

Special offers

The API returns an XML, however the module returns a ready to use JS object.

Flight Search

Requirements for API access

Please note, that md5 signature is generated automatically by this module, so you don't need to do it in your code.

flight.search(params, callback)

Request initialization

flight.results(params, callback)

Getting search results

flight.click(params, callback)

Getting a link to the agency website

Affiliate statistics

statistics.balance(callback)

Balance

statistics.payments(callback)

Your payments

statistics.sales(options, callback)

Your stats

statistics.detailedSales(options, callback)

Your stats by date and marker

Price map

map.directions(options, callback)

Supported routes

map.prices(options, callback)

Prices

Directions

directions.airline(options, callback)

Popular airline routes

directions.city(options, callback)

Popular routes from city

Misc

whereami(options, callback)

User location by IP address

You don't need to specify callback param in options since the module does this automatically.

currency(callback)

Currency exchange rate related to Russian Ruble (in Russian)

Example

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);
});

Tests

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

License

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.