Using the FlightXML API, programs can query the FlightAware live flight
information and recent history datasets.
Queries for in-flight aircraft return a set
of matching aircraft based on a combination of location, flight or tail number,
origin and/or destination airport, aircraft type, and/or a low-to-high range of
altitude and/or ground speed, among others. For each matching aircraft, data
returned includes the flight or tail number, the aircraft type, origin and
destination, time the last position was received, and the longitude, latitude,
groundspeed, and altitude of that position. Matching flights' flight tracks can
be requested as well.
For airports, FlightXML queries can return a list of scheduled flights,
flights that have departed, flights that are enroute to the airport, and flights
that have arrived at the airport.
Example Applications
Possible uses of FlightXML include:
Integrate FlightXML radar data with your existing flight dispatch software.
Create a customized alerting system based on the current status of your fleet.
Streamline flight planning by showing common routes as cleared by air traffic control between two airports.
Add real flight data to your simulations.
Show flight tracks in Google Earth.
Create visualizations of traffic patterns.
Add live flight information to your company's website.
Authentication
To access FlightXML 2.0, all requests must include a username and FlightXML Key (don't have one?).
This data is transmitted via the "basic" HTTP Authentication standard, which is sent to the FlightXML server as a part of each HTTP request.
The web service libraries available in most programming languages allow you to directly specify a username and password as an argument for the request, so that the authentication is transparent to your application as it makes requests. However, with some libraries it may be necessary to manually encode the "user:key" in base64 and send the result in the "Authorization" header as part of each HTTP request.
If data security is a concern, all FlightXML services are also available over SSL by simply substituting "https" as the protocol for any flightxml.flightaware.com URLs.
Web Services / SOAP / WSDL
The primary protocol recommended for use with FlightXML 2.0 is the "Simple Object Access Protocol" (SOAP). Most modern SOAP implementations support use of "Web Services Description Language" (WSDL) definition file, which greatly simplifies accessing web services.
Although you can read the WSDL and generate SOAP queries manually, it is recommended that you develop your
applications using a SOAP library that automatically parses the WSDL and populates your application namespace
with the FlightXML functions.
It is strongly suggested that you ensure that your applications cache the WSDL
file so that it is not necessary to fetch and parse the WSDL for every request or instance of your
application. This will vastly improve the performance and efficiency of your application.
The FlightXML 2.0 WSDL uses the "Document/Literal wrapped" method for encoding SOAP requests and responses.
This is a newer method that recent SOAP industry standards dictate should be used instead of the older
"RPC/Encoded" method that was used by the FlightXML 1.0 WSDL. Most modern SOAP client libraries fully
support this newer method, although some older SOAP libraries are not yet compatible. The SOAP client
libraries listed in the examples section have been tested to be compatible.
REST / JSON
FlightXML 2.0 can also be accessed using a light-weight "Representational state transfer" (REST) inspired protocol that returns its responses encoded in "JavaScript Object Notation" (JSON) format. This allows FlightXML to be used in environments in which it is inconvenient or impossible to invoke SOAP services, such as mobile phone applications, web browser applications, or server-side JavaScript environments.
To access any method, simply perform either a GET or POST request to http://flightxml.flightaware.com/json/FlightXML2/METHODNAME using standard CGI-style representation of the arguments. All requests made must supply the username and API Key as a "basic" Authorization HTTP header.
For example, the following URL is how you might request the current weather at John F. Kennedy airport (KJFK) in New York: http://flightxml.flightaware.com/json/FlightXML2/MetarEx?airport=KJFK&startTime=0&howMany=1&offset=0
Requests can also optionally returned in "JSONP" format, allowing a web page to load the response in a way that avoids the same-domain security restrictions enforced by some browsers. Simply specify the optional argument "jsonp_callback" with a value that is the name of the JavaScript function that should be invoked with the JSON data.
Start building a great new aviation app with FlightXML 2.0.
Any Microsoft CLR .NET language should be usable to make requests to FlightXML 2.0, however this example is using C#. The procedure for using other languages may vary slightly. The steps described here use the command-line utilities to generate the WSDL stub and compile, but the steps can be adapted for use within the Visual Studio IDE.
Requirements
Microsoft Visual Studio 2003 or newer
Save the following file as test.cs, but substitute your actual username and API key:
using System.Net;
class test {
public static void Main(string[] args)
{
FlightXML2 df = new FlightXML2();
df.Credentials = new NetworkCredential("sampleUser", "abc123abc123abc123abc123abc123");
df.PreAuthenticate = true;
// get the flights currently enroute.
EnrouteStruct r = df.Enroute("KAUS", 10, "", 0);
foreach (EnrouteFlightStruct e in r.enroute) {
System.Console.WriteLine(e.ident);
}
// get the weather.
System.Console.WriteLine(df.Metar("KAUS"));
}
}
on RHEL/Fedora based systems: yum install php-nusoap
on FreeBSD systems: cd /usr/ports/net/nusoap && make install
otherwise download from the SourceForge project site listed above
Save the following file as testsoap.php, but substitute your actual username and API key:
<?php
require_once( "nusoap/nusoap.php" );
$username = 'sampleUser';
$apiKey = 'abc123abc123abc123abc123abc123abc123';
$baseUri = "http://flightxml.flightaware.com/soap/FlightXML2";
date_default_timezone_set('UTC');
$client = new nusoap_client("$baseUri/wsdl",'wsdl');
$client->setCredentials($username,$apiKey);
if ( $client->getError() ) {
die "Soap Constructor Error:" . $client->getError();
}
// get the weather.
$params = array("airport" => "KAUS");
$result = $client->call( "Metar", $params);
if ($client->fault) { //soap_fault
die "Soap Fault: ". $client->fault->faultcode . "(" . $client->fault->faultstring . ")";
}
elseif ( $client->getError() ) {
die "Soap Error: " . $client->getError();
}
else {
print_r($result);
}
?>
Perl
The Perl CPAN module SOAP::WSDL is a modern SOAP client that fully supports Document/Literal services.
Requirements
Perl5 or above
SOAP::WSDL (tested with 2.00.10)
On FreeBSD systems: cd /usr/ports/devel/p5-SOAP-WSDL && make install
On RHEL/Fedora based systems: rpm -Uvh perl-SOAP-WSDL-2.00-xx-y.zz.rf.noarch.rpm (from the RPMForge repository)
Otherwise: perl -MCPAN -e 'install SOAP::WSDL'
Save the following file as testwsdl.pl, but substitute your actual username and API key:
#!/usr/bin/perl
use strict;
use SOAP::WSDL 2.0;
my $username = "sampleUser";
my $apiKey = "abc123abc123abc123abc123abc123";
my $baseUri = "http://flightxml.flightaware.com/soap/FlightXML2";
sub SOAP::WSDL::Transport::HTTP::get_basic_credentials {
return $username => $apiKey;
}
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return $username => $apiKey;
}
# Check if the SOAP result is an exception.
sub is_fault ($) {
my $result = shift;
return !defined($result) || ref($result) eq 'SOAP::Fault' || !defined($result->result);
}
# Singleton arrays are changed by SOAP::WSDL into scalars, making you handle either type.
sub coerce_arrayref ($) {
my $val = shift;
my @result = (ref($val) eq 'ARRAY' ? @$val : $val) if defined($val);
return @result;
}
my $soap = SOAP::WSDL->new( wsdl => "$baseUri/wsdl" );
my $enroute = $soap->call('Enroute', EnrouteRequest => {'airport' => "KSMO", 'howMany' => 10, 'filter' => "", 'offset' => 0});
die if is_fault($enroute);
print "Aircraft en route to KSMO:\n";
my @flights = coerce_arrayref($enroute->result->{enroute});
foreach my $flight (@flights) {
print $flight->{'ident'} . " (" . $flight->{'aircrafttype'} . ") \t" .
$flight->{'originName'} . " (" . $flight->{'origin'} . ")\n";
}
Run commands:
./testwsdl.pl
The Perl CPAN module SOAP::Lite is an old and well-known SOAP client for Perl, however it is not especially well-suited for modern "Document/Literal" SOAP services. However, it can be used if you are willing to make calls to explicitly declare the types of all function arguments using the SOAP::Data method. The "stubmaker.pl" utility and the SOAP::Lite WSDL support cannot be used.
Requirements
Perl5 or above
SOAP::Lite (tested with 0.710.10)
On RHEL/Fedora based systems: yum install perl-SOAP-Lite
On FreeBSD systems: cd /usr/ports/net/p5-SOAP-Lite && make install
Otherwise: perl -MCPAN -e 'install SOAP::Lite'
Save the following file as testlite.pl, but substitute your actual username and API key:
#!/usr/bin/perl
use strict;
use SOAP::Lite;
my $username = "sampleUser";
my $apiKey = "abc123abc123abc123abc123abc123";
my $baseUri = "http://flightxml.flightaware.com/soap/FlightXML2";
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return $username => $apiKey;
}
my $soap = SOAP::Lite->default_ns($baseUri)->proxy("$baseUri/op")->autotype(0);
my $enroute = $soap->call("Enroute",
SOAP::Data->name("airport" => 'KSMO'),
SOAP::Data->name("howMany" => 10),
SOAP::Data->name("filter" => ''),
SOAP::Data->name("offset" => 0)
);
die if !defined($enroute) || $enroute->fault;
print "Aircraft en route to KSMO:\n";
my $flights = $enroute->result->{enroute};
foreach my $flight (@$flights) {
print $flight->{'ident'} . " (" . $flight->{'aircrafttype'} . ") \t" .
$flight->{'originName'} . " (" . $flight->{'origin'} . ")\n";
}
on RHEL/Fedora based systems: yum install python-suds
Save the following file as test.py, but substitute your actual username and API key:
#!/usr/bin/python
import sys
from suds import null, WebFault
from suds.client import Client
import logging
username = 'sampleUser'
apiKey = 'abc123abc123abc123abc123abc123abc123'
url = 'http://flightxml.flightaware.com/soap/FlightXML2/wsdl'
logging.basicConfig(level=logging.INFO)
api = Client(url, username=username, password=apiKey)
#print api
# Get the weather
result = api.service.Metar('KAUS')
print result
# Get the flights enroute
result = api.service.Enroute('KSMO', 10, '', 0)
flights = result['enroute']
print "Aircraft en route to KSMO:"
for flight in flights:
print "%s (%s) \t%s (%s)" % ( flight['ident'], flight['aircrafttype'],
flight['originName'], flight['origin'])
This example is a static HTML page using JavaScript and jQuery to access FlightXML2 over its JSON interface.
We recommend that this technique be only used in protected Intranet environment, since embedding your
FlightXML API key in public web pages will allow other users to copy your key and make unauthorized use against your account.
Requirements
Web browser (tested with Firefox, Safari, Chrome. Not compatible with Internet Explorer)
Web server (static HTML)
Save the following file as test.html, but substitute your actual username and API key:
<html>
<head>
<!--
This example uses:
* the FlightXML2 FlightInfoEx and DecodeFlightRoute functions over REST:
http://flightaware.com/commercial/flightxml/
* Google Maps API:
http://code.google.com/apis/visualization/documentation/gallery/map.html
* jQuery, hosted by Google API
-->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
var fxml_url = 'http://YOUR_USERNAME:YOUR_API_KEY@flightxml.flightaware.com/json/FlightXML2/';
google.load("visualization", "1", {packages:["map"]});
// When the button is clicked, fetch the details about the entered flight ident.
$(document).ready(function() {
$('#go_button').click(function() {
$.ajax({
type: 'GET',
url: fxml_url + 'FlightInfoEx',
data: { 'ident': $('#ident_text').val(), 'howMany': 1, 'offset': 0 },
success : function(result) {
// display some textual details about the flight.
var flight = result.FlightInfoExResult.flights[0];
$('#results').html('Flight ' + flight.ident + ' from ' + flight.origin + ' to ' + flight.destination);
// display the route on a map.
fetchAndRenderRoute(flight.faFlightID);
},
error: function(data, text) { alert('Failed to fetch flight: ' + data); },
dataType: 'jsonp',
jsonp: 'jsonp_callback',
xhrFields: { withCredentials: true }
});
});
});
// Fetch the planned route for a specified flight_id.
function fetchAndRenderRoute(flight_id) {
$.ajax({
type: 'GET',
url: fxml_url + 'DecodeFlightRoute',
data: { 'faFlightID': flight_id },
success : function(result) {
// Initialize a data table using the Google API.
var table = new google.visualization.DataTable();
table.addColumn('number', 'Lat');
table.addColumn('number', 'Lon');
table.addColumn('string', 'Name');
// Insert all of the points into the data table.
var points = result.DecodeFlightRouteResult.data;
table.addRows(points.length);
for (rowid = 0; rowid < points.length; rowid++) {
table.setCell(rowid, 0, points[rowid].latitude);
table.setCell(rowid, 1, points[rowid].longitude);
table.setCell(rowid, 2, points[rowid].name + ' (' + points[rowid].type + ')' );
}
// Render the data table into a map using Google Maps API.
var map = new google.visualization.Map(document.getElementById('map_div'));
map.draw(table, {showTip: true, showLine: true, lineWidth: 3, lineColor: '#009900'});
},
error: function(data, text) { alert('Failed to decode route: ' + data); },
dataType: 'jsonp',
jsonp: 'jsonp_callback',
xhrFields: { withCredentials: true }
});
}
</script>
</head>
<body>
<form onsubmit="return false;">
<p>Enter a flight ident to track:
<input type="text" name="ident" id="ident_text" value="COA423" />
<input type="submit" id="go_button" value="Go" />
</p>
</form>
<div id="results"></div>
<div id="map_div" style="width: 400px; height: 300px"></div>
</body>
</html>
This example is a Node.JS console application written in Javascript that accesses FlightXML2 over its JSON interface.
(2011-02) Changed GetHistoricalTrack, DecodeFlightRoute, MapFlightEx, and AirlineFlightInfo to allow "ident@departureTime" syntax to optionally be used instead of a faFlightID, saving the need to explicitly use GetFlightID first.
(2011-02) Changed FlightInfo, FlightInfoEx, InFlightInfo, GetLastTrack, GetFlightID, TailOwner, and MapFlight to handle codeshare or alternate ident lookups automatically. GetHistoricalTrack, DecodeFlightRoute, MapFlightEx, and AirlineFlightInfo allow codeshare and alternte idents when using the "ident@departureTime" syntax.
(2012-03) Added support for Australian airspace. To receive these flights, you must use the API key request page to obtain a new key and agree to the distribution terms. Otherwise such flights may appear in your results with an ident of "BLKFA" and its other fields will be blank/zero.
(2012-04) Enhanced FlightInfoEx to allow a faFlightID to be requested.