API 101: Defining Travel and Booking Comparisons with APIs (7)
This module will focus on travel booking sites, OpenSky API, and Skyscanner parameters to create travel applications.
There are a number of travel-related APIs on the market. Depending on your use case, there are public transportation, hotel, car rental, rail booking, flight booking, restaurant reservation, tours and attractions, and airport transfer APIs.
When you want to book a flight, you search for flights on the airline’s website and choose a departure city, return city, dates, cabin class, and other variables available. Based on this request, you are presented with a host of options to choose from.
This process takes the same turn with travel booking sites, except that they are able to aggregate thousands of flights and destinations from the airline’s website and showcase a number of options available on the market so that a user can compare them and make an informed choice.
Travel APIs provide application users with access to the latest information about availability from hotels and airlines. Unlike our other API examples, there are almost no 'free' APIs in the travel industry.
Get real-time flight and aircraft info with OpenSky API
OpenSky API is an open API that lets you retrieve live airspace information for research and non-commercial purposes. The API comes with Java and Python and can be used with any language that supports JSON-based REST APIs.
All tracking information for an aircraft is retrieved as state vectors in the form of a JSON object. The flight state information is derived from Automatic Dependent Surveillance-Broadcast (ADS–B) and Mode S messages. In ADS-B, each transponder is identified with a unique ICAO 24-bit address, displayed in its 6-character hex representation.
OpenSky provides specific documentation for its REST API. It also provides access to an aircraft database.
OpenSky API allows accessing its API without using credentials subject to certain limitations. Anonymous users can only get the most recent state vectors and can only retrieve data with a time resolution of 10 seconds.
The root URL of the REST API is:
To get information for all aeroplanes or times:
The response is a really long list:
A better way is to request state vectors for particular airplanes or times using the following request parameters:
Example query with time and aircraft British Airways:
To query a certain area, we'll define a bounding box of World Geodetic System (WGS84) coordinates for London (51.2224, -0.7663, 51.7908, 0.5109).
A bounding box is an area defined by two longitudes and two latitudes, where Latitude is a decimal number between -90.0 and 90.0 and Longitude is a decimal number between -180.0 and 180.0.
The standard format of a bounding box is:
The response is a JSON object with time which the state vectors are associated with and state properties.
Each row on the states property represents a state vector and contains the following fields:
OpenSky API call also retrieves flights in time interval. The begin, endtime interval retrieve flights as Unix time.
The given time interval must be within two hours. If no flights are found for the given time period, HTTP status 404 - Not found is returned with an empty response body.
For example, send a request to get flights from 12 pm to 2 pm on Dec 03, 2021:
The response is a JSON array of flights where each flight is an object with the following properties:
You can proceed to make further API calls for:
- flights by aircraft — retrieve flights for a particular aircraft within a certain time interval
- Arrivals by Airport — retrieve flights for a certain airport which arrived within a given time interval
- Departures by Airport — retrieve flights for a certain airport which departed within a given time interval, or
- Track by Aircraft — retrieve the trajectory for a certain aircraft at a given time.
Using Skyscanner Flight Search APIs
Skyscanner is a metasearch engine (or search aggregator) that lets travelers look for flights and hotels at the best rates from its database of prices from a large number of suppliers.
A metasearch engine is an online information retrieval tool that sends search queries to many different sources and uses the data to produce its own results.
Airline websites hold data pertinent to them. Here's how Skyscanner works - Skyscanner uses APIs to collect flight and hotel prices from hotels and airlines. It interacts with the suppliers' websites to access their database to see availability, cost, flight time, route popularity, etc.
Via the API, It requests data from each one of these sites and aggregates flight details to provide the response. If you make a booking, Skyscanner will use APIs to confirm with the provider it was sourced from.
How to find flight routes and best prices via the Skyscanner API
To get started with the API integration, check their documentation here.
Skyscanner APIs require an access token to authenticate the account with the provider when making a request.
Compared to other APIs previously reviewed, Skyscanner APIs are exposed to the strategic business partners through a commercial agreement only, and not available publicly.
To access Skyscanner's APIs, you need to contact them to request an API key via the contact form. Partners are selected on a case-by-case basis.
The API keys have fixed-rate limits of:
- Flights Live Pricing: 100 per minute
- Flights Browse: 500 per minute
- Car Hire: 100 per minute
Skyscanner provides its partners with RESTful API that supports both XML and JSON formats. It requests that you are accessing the APIs through HTTPS**.**
In order to get the response in XML or JSON, the HTTP Request “Accept” header field can be used to specify the content received. Using: application/json, application/xml will result in the content being returned in the preferred format.
The primary use of the Skyscanner API is to search flights. Searching flights via Skyscanner API is broken down into separate endpoints:
- Flights Browse Prices
- Live Prices - Flights Live Prices for live prices from all suppliers for the requested flight itinerary (in the selected market), and Hotels Live Prices for live prices from all our suppliers for hotel deals (in the selected market).
- Localization - Skyscanner services by market, language, and currency, so these three parameters must be added to every request.
- Places - by country, city, airport
Choosing between Live Flight Search or Browse Flight Prices Endpoint
Given the large number of suppliers queried for quotes, the Live Pricing may take up to a minute to return all the results. Thus, Skyscanner recommends starting with the cache prices API (Browse Flight Prices) unless you require exact prices.
From the cache prices, you can retrieve the cheapest quotes, cheapest routes, cheapest dates and initiate Browse Requests. This is great for searching and comparing different dates and different destinations.
First, let's browse for some flights from the cached prices.
Retrieve cheapest quotes from Skyscanner cached prices
Skyscanner API allows the application to get access to travel companies’ database systems to check for slots’ availability based on the requested information.
You have to pass all needed parameters for search in the request, such as country, currency, origin and destination places, dates, etc.
Browse Flight Prices API endpoints which return information about the cheapest quotes, routes, or dates from the Skyscanner cache.
Let's use the Browse Quotes endpoint to send a request for London to Paris anytime from 16th November to 22nd December.
To make an API call, pick an endpoint and fill in the parameters, including your apiKey
Let's get into the details of this request and specify the required parameters.
To retrieve the market countries that Skyscanner supports:
To retrieve the currencies supported
To retrieve the locales that supported to translate your content:
To specify the OriginPlace and DestinationPlace, the Place ID used in Browse Requests should be a combination of Place and Type.
We'll use the Skyscanner Code for London city LOND-sky, and Paris PARI-sky for the outbound/inbound dates specified in the format YYYY-MM-DD.
You must include the API key in all API requests to the server, either as a parameter in the query or the request header.
Flights Live Prices
To get the most out of Skyscanner, use the Live Flight Search to provide an up-to-date price comparison as it has more accurate pricing information for a given route on specific dates.
The request contains details of the locations, dates, passengers, cabin class, and user details. These parameters define the session, and cannot be changed within the session (except for passenger numbers).
You can try it by using the Run in Postman button on Skyscanner to create a session, poll results, get or poll booking details.
To get data on hotels and accommodations, apply for Booking.com API affiliate program and receive your API access. You become their affiliate partner and receive part of the booking fee.
Alternatively, the Agoda Affiliate Program belongs to Booking Holdings and also provides access to accommodation data.
You can also apply for the Expedia Rapid APIs affiliate program and receive your API access. The process is similar to Booking.com as you get an affiliate fee for accommodation booking. Expedia has both SOAP and RESTful APIs for its partners. SOAP is a protocol, unlike REST, and only allows XML as the data exchange format.
Use Sabre API targeted at hospitality, travel agencies and airline to create a customized travel experience. To take an idea from start the finish, these third-party APIs form the basis for quick development.
In this module, we successfully covered travel and booking APIs and parameters for Skyscanner and OpenSky. In the next module, we will go over Facebook APIs and its application in real-world scenarios.
📎 PREVIOUS MODULE - Get started with Google Maps API
I'm Juliet 'Hiri' Edjere, a no-code expert focused on design, business development and building scalable solutions with minimal coding knowledge.
I document all things product stories, MVP validation, and how designs, data and market trends connect to one another.