Experimenting with some KLM APIs by building a small data collection tool which outputs a daily report tracking flight offers for some different destinations.

KLM Offers API

KLM / Air France have some interesting APIs. Some can show you the live status of flights. Others open up access to flight booking / planning data for their own & codeshare flights.

One endpoint in this “Offers API” is the lowest-fares-by-destination. It gives the “lowest fare” for a given date interval and set of destinations. It also suggests a roundtrip trip length that minimises price.

An example request and response taken from the API docs. It could be interesting to try building something with this…

Using the API to Explore Questions

Assume we’re interested in KLM/codeshare flights departing Amsterdam Schiphol Airport. We’re open to roundtrips with the length recommended to us and connecting flights are ok.

  • If I buy tickets today, when are the lowest fares for the destinations I am interested in?
  • What are the trends in pricing – how does today’s offer compare with past offers?

A Small Data Logger

A small script is written in PHP, with a MySQL database for data storage – code here on GitHub. The database holds some configuration data (like destinations to track) and some airport metadata. The general architecture:

  • a cron task runs the cli script daily
  • script calls API and dumps response into a table apicalls
  • INSERT trigger extracts data from response into table lowestfaredestination for analysis
  • app queries lowestfaredestination to generate daily HTML report

The Report

The latest daily report output can be found here. After choosing some destinations from the list, the report is divided in two. First we can compare the best fare departing in the three date intervals (0-4, 4-8 or 8-12 months from today):

report showing best fares available now

The second view shows how the best fare in any interval changes over time. For example, Riga is a new opportunity – a drop in price for the best fare if buying today. San Francisco shows a period where the best fare dipped, but is now a missed opportunity:

report showing fare trends over time

The mean is the best fare (in any interval) over the preceding 90 days. The percentage change is the current price compared with this average. It gives some indication of how good the deals are today compared with historic data.

Further Thoughts & Improvements

  • additional insights from the data
  • email alerts based on price drops
  • the data has been collecting for the a month now, it would be interesting to check back in a year and explore patterns, seasonalities etc
  • sometimes the API “disobeys” the date interval in the request. Also sometimes doesn’t give back an offer for each destination: want to try and debug why this is