This post shares information about GraphQL, including how to work with it.
Travelpayouts presents a GraphQL service for partners to get our Flight Data API travel insights.
Access to GraphQL is open to all partners signed up for 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 that 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 allowing you to discover possibilities of our GraphQL API service: http://api.travelpayouts.com/graphql/v1/playground.
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 Headers in the X-Access-Token field.
{ "X-Access-token": "TypeHereYourAffiliateToken" }
In the request, you need to specify both parameters to the endpoint and the 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: "2026-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-costers in July 2026.
The response example:
{ "data": { "prices_one_way": [ { "departure_at": "2026-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 Headers in the X-Access-Token field to view the contents of the tab.
Example Request in PHP
<?php
// Define the GraphQL query as a string
$query = <<<GQL
{
prices_one_way(
params: {
origin: "BCN"
destination: "LON"
depart_months: "2025-07-01"
no_lowcost: true
}
paging: {
limit: 3
offset: 0
}
sorting: VALUE_ASC
) {
departure_at
value
trip_duration
ticket_link
}
}
GQL;
// Set the headers and endpoint
$headers = [
"Content-Type: application/json",
"X-Access-Token: InsertYourAffiliateTokenHere"
];
$endpoint = "https://api.travelpayouts.com/graphql/v1/query";
// Initialize a cURL session
$ch = curl_init($endpoint);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['query' => $query]));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo "cURL error: " . curl_error($ch);
} else {
// Decode and display the response
$decodedResponse = json_decode($response, true);
print_r($decodedResponse);
}
// Close the cURL session
curl_close($ch);
?>