I’m developing an app that needs to look up country codes (ISO-3166 alpha2) based on IATA-codes (http://en.wikipedia.org/wiki/IATA_airport_code).
Is there an (preferably free) API for that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m submitting here a incomplete solution, both as way to address the IATA-to-Contry-Code question at hand, and to bring attention to what may be a underused resource for structured content: I’m talking about Freebase !
This is incomplete in the sense that not all IATA codes are included (though I’m guessing a relatively high coverage) or not all have a country code assigned to them (alas a more common occurrence).
The API I wish to suggest is the Freebase MQL Read Service.
This free service works by sending an HTTPS request with a parameter that expresses a query in MQL (Metaweb Query Language), and receiving a JSON object with the desired results.
Specifically the request looks like
for readability I’m showing the corresponding MQL with indentation on multiple lines; same thing as above only better layout.
And the response looks like the following:
This solution was “whipped-up” in approximately 30 minutes by drilling into the Freebase
/aviation/airporttype and using various tools I describe briefly below.Note that this is a generic approach, applicable to various queries: rather than matching IATA airport codes to ISO country codes, we could, for example, get the list of the bridges build before 1950 with a span exceeding 500 feet, or look up the famous musicians born in a given city etc. Furthermore, AFAIK, the Freebase API and information is freely available. Beware, however, that there are some limitations (and some advantages!) to the content found at Freebase as compared with that obtained from specialized sources.
The information obtained from Freebase may not be as authoritative, complete or current as that obtained with APIs and Data Extracts from specialized sources. This limitation speaks to the quasi universal breadth of the information gathered at Freebase in a collaborative, wiki-like, fashion, by a mostly volunteer task force, compared with the focused, often single-purposed, information gathering performed by paid professionals at various trade organizations such as, say the IATA or the International Maritime Organization (IMO). On the other hand, Freebase, with its semantic representation of the data, provides ways of connecting bits of information in powerful ways. Whereby the authoritative sources provide mostly “tabular” data, Freebase queries can match apparently unrelated pieces of information. For example, whereby the IMO probably produces lists of seaports with their annual tonnage, their number of terminals and such, Freebase can also find, say, the films that were shot in these ports or the famous writers who were born there.
But enough with disclosures, let’s see how one can produce these queries
For example, one may peek into various airport instances found for the Airport Type on Freebase
Here’s the schema for our Airport Type example.
See how the tree shown in the “Add new column” section (shown after pressing the “+”) allows drilling down the schema of the type that we start with or of types connected to it.
In the case of Airports, I quickly removed the “image”, “article” and “airline”-related fields, to make room, and added the IATA code, and drilled in the “Location” to find the Country and from there the ISO code. This connection to “Country” was a bit tricky, I had to look into the “Contained by” which itself is another “Location” and, using the “More” brought up the “Country” type.
I’d like to finish with the following suggestion: Rather than integrating this online API to your application, it is sometimes possible to download the complete list and to create a local database with it. In this fashion it may be possible to complement the data by adding rows and/or filling empty columns. This approach is particularly applicable to the IATA/Airport example -after all the list of airports and their underlying codes is relatively small and does not vary all that frequently-. This approach of course may require the local DB to be refreshed and otherwise maintained occasionally, but it removes the requirement of the online, real-time, connection to Freebase.