Learn how to search for an airport through our API

The sooner or later, when you start your own flight search, flight scraping or travel hacking project, you’ll realize that you need accurate information about airports, their IATA codes and location. While this might sound like an easy to accomplish task you’ll soon realize that this can be a true rabbit hole. In this blog post, I’ll show you what the challenges are and how you could overcome them with our free API.

🥊 The challenge

Let’s assume you need a list of all IATA airports with their location to display them on a map. This task sounds easy, right?

One extremely popular database is the openflights.org database. It’s basically a compilation of two other publicly available databases. The OurAirports database and the DAFIF database which used to available to the public. The openflights.org database comes with a lot of useful information such as IATA code, ICAO code, Latitude, Longitude and much more. If you download the extended data file from GitHub you’ll get over 12.000 air terminals, train stations, and ferry terminals, each making up a row in the comma-delimited file.

1
2
3
1,"Goroka Airport","Goroka","Papua New Guinea","GKA","AYGA",-6.081689834590001,145.391998291,5282,10,"U","Pacific/Port_Moresby","airport","OurAirports"
2,"Madang Airport","Madang","Papua New Guinea","MAG","AYMD",-5.20707988739,145.789001465,20,10,"U","Pacific/Port_Moresby","airport","OurAirports"
3,"Mount Hagen Kagamuga Airport","Mount Hagen","Papua New Guinea","HGU","AYMH",-5.826789855957031,144.29600524902344,5388,10,"U","Pacific/Port_Moresby","airport","OurAirports"

Possible downsides of using the openflights.org database

Don’t get me wrong, the openflights.org database is extremely comprehensive and impressive and also creates a solid foundation for many projects, including the travelhackingtool.com. However, it shouldn’t be omitted that it also has some possible downsides.

Data accuracy

Keeping a user contributed-list of thousands of airports accurate can be a very tedious task and it’s needless to say that errors will occur the sooner or later. Theses most often come from users, which had mistyped something or just haven’t been very careful. Let’s look at some examples, of what this might lead to.

Duplicate entries

Some airports like Vilamendhoo occur multiple times in the file, making it hard to choose, which one is the most accurate one. While one might be more likely than the other, it’s ultimately up to the application developer to decide.

1
2
3
4
5
6
6468 Vilamendhoo Vilamendhoo Maldives \N \N 73.01910987 3.609654755 0 1 U Arctic/Longyearbyen unknown User
6469 Vilamendhoo Vilamendhoo Maldives \N \N 3.609654755 73.01910987 0 5 U Indian/Maldives unknown User
6470 Vilamendhoo Vilamendhoo Maldives \N \N 3.484 73.802 0 5 U Indian/Maldives unknown User
6471 Vilamendhoo Vilamendhoo Maldives \N \N 73.801 3.801 0 5 U \N unknown User
6473 Vilamendhoo Vilamendhoo Maldives \N \N 0 0 0 5 U \N unknown User
6474 Vilamendhoo Vilamendhoo Maldives \N \N 3.8 73.8 0 5 U Indian/Maldives unknown User
Incomplete data and test entries

Some airports which have been entered lack an IATA or ICAO code or are all together just dummy entries.

1
2
11063 TEST TSST Switzerland \N \N 47.251384 8.956672 258 1 U \N unknown User
11064 TEST TSST Switzerland \N \N 47.251384 8.956672 258 1 U \N unknown User
Inaccurate data

One of the biggest problems I had encountered while using the openflights.org database is the inaccuracy of the location data. Oftentimes latitude and longitude are in the wrong order, leading to highly inaccurate results. Did you know that Boston is located in Antarctica?

1
13555 Logan Boston United States \N \N -71.006389 42.363056 20 -5 U \N \N \N

All of these examples clearly show that you shouldn’t fully rely on the data provided, as it contains some serious flaws. One other problem, you’ll soon enough realize is that searching those huge CSV files in Excel or even using Python can become quite cumbersome.

Handling of .dat and .csv file within an application is tedious

You’ll soon enough realize that looking up a single airport in this huge data file can be quite cumbersome and slow, especially considering that a simple search sometimes returns multiple entries (just look at our Vilamendhoo example). Even if you import them into a database you will have an additional piece of software that could fail.

🩹 Travelhackingtool.com to the rescue

Having experienced all these frustrating parts of creating a travel app myself, led me to create travelhackingtool.com. It’s the only free and reliable aviation API. We wanted to take the pain out of writing travel hacking or aviation applications and give you a head start when developing your own. We, therefore, constantly aggregate publicly available information, clean it up, verify it and provide it to you through an easy to use API.

Let’s check out how easy it is to use our API

Using our travelhackingtool.com REST API is extremely easy. I’ll walk you through the three simple steps:

  1. Create yourself a Rapid API account
  2. Subscribe to our Travel Hacking Tool API on Rapid API (Choose the Basic Plan to begin with) and get an API token
  3. Consume our API

Let’s say you want to look up some airport details of the airport with IATA code MUC in python. Simply use the following snippet.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import requests

url = "https://travel-hacking-tool.p.rapidapi.com/api/airports/"

querystring = {"code":"MUC"}

headers = {
'x-rapidapi-host': "travel-hacking-tool.p.rapidapi.com",
'x-rapidapi-key': "YOUR-API-TOKEN"
}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

The matching response will look like this:

1
2
3
4
5
6
7
8
9
{
    "code": "MUC",
    "name": "Franz Josef Strauss Airport",
    "latitude": 48.353004,
    "longitude": 11.790143,
    "time_zone": "Europe/Berlin",
    "city_code": "MUC",
    "country": "DE"
}

And what’s best is that you can rest assured that the response is accurate and up to date.

Bonus point

You can search not just based on an IATA code, but also based on a ISO country code. Simply change the query string.

1
querystring = {"country":"DE"}

Wrapping things up

We are curious to see how you are using our free API, feel free to tell us about your latest project through the contact us section or by leaving a comment.