Aviasales GraphQL for access to Flights Data API

Travelpayouts presents a GraphQL service for partners to get our Flight Data API travel insights. 

Access to GraphQL is open to all partners registered with Travelpayouts and connected to the Aviasales program.

Please note, API methods use limits, which are described in the article API rate limits.

What is GraphQL

GraphQL is a query language which allows you to retrieve all the needed data with a single query. You can use it to retrieve more data with fewer requests than with the REST API. You can learn more about how GraphQL works in the official documentation.

We prepared an interface which will allow you to discover possibilities of our GraphQL API service: http://api.travelpayouts.com/graphql/v1/playground.

mceclip3.png

How Aviasales GraphQL API works

Let’s look at a simple example in a playground of how you can use our GraphQL service.

Each request should contain your API token, pass it to the Header in the X-Access-Token field.

{
  "X-Access-token": "TypeHereYourAffiliateToken"
}

mceclip5.png

In the request, you need to specify both parameters to the endpoint and fields that you want to return in the response. 

Here’s a request example:

{
  prices_one_way( #in parentheses are the parameters responsible for the request
    params: {
        origin: "BCN"
        destination: "LON"
        depart_months: "2022-07-01"
        no_lowcost: true
        }
    paging: {
        limit: 3
        offset: 0
      }
    sorting: VALUE_ASC
  )
#then list the response parameters
 {
  departure_at
  value
  trip_duration
  ticket_link
 }
}

With the query above we can get the three cheapest tickets from Barcelona to London excluding low-costs in February 2022. 

The response example: 

{
  "data": {
    "prices_one_way": [
      {
        "departure_at": "2022-07-10T22:40:00+02:00",
        "value": 9943,
        "trip_duration": 0,
        "ticket_link": "/BCN1007LON1?t=TP16574856001657529100000725BCNLISLGW_84743a1ebf337c73dc4f87f5ee133eb0_9943&search_date=09032022&expected_price_uuid=e695fb09-1d34-4b8f-9285-0702ef9ee216&expected_price_currency=usd"
      }
    ]
  }
}

As requested in the query, in the response we get a price, date of departure, duration of the trip and a code that can be added to the URL https://www.aviasales.com/search/, to open the search results on the given route on Aviasales.

A list of all available queries with parameter descriptions and response fields can be found on the Docs tab. Please note that you need to pass your API token to the Header in the X-Access-Token field to view the contents of the tab. 

mceclip0.png

mceclip1.png

GraphQL allows you to get all the necessary data with a single query, while it would require three responses in the REST API. For example, the following query returns for three destinations at once: 

query {
  MOW_AER: prices_round_trip(
    params: {
      origin: "LON"
      destination: "BCN"
    }
    sorting: ROUTE_WEIGHT_DESC
    paging: {
      offset: 0
      limit: 3
    }
  )
  {
    departure_at
    return_at
    value
  }
  MOW_LED: prices_round_trip(
    params: {
      origin: "LON"
      destination: "PAR"
    }
    sorting: ROUTE_WEIGHT_DESC
    paging: {
      offset: 0
      limit: 3
    }
  )
  {
    departure_at
    return_at
    value
  }
  MOW_SIP: prices_round_trip(
    params: {
      origin: "BCN"
      destination: "PAR"
    }
    sorting: ROUTE_WEIGHT_DESC
    paging: {
      offset: 0
      limit: 3
    }
  )
  {
    departure_at
    return_at
    value
  }
}