Gal Ratner
Gal Ratner is a Techie who lives and works in Los Angeles CA and Austin TX. Follow galratner on Twitter Google
Search for flight information with the Bing API

The Bing API allows developers to query the Bing Engine.  Queries can be sent using JSON, XML or SOAP. 

In order to query Bing you will need an Application ID available on the Bing Developer Center.  You will also need to agree to the terms of service.
The Bing API includes support for Images, Answers, news, Phonebook, related, Spellcheck, Translation, Video and web results.

In this example we will use the InstantAnswer SourceType in order to query for specific flight information. The InstantAnswer response can contain Encarta or FlightStatus as its ContentType, depending on the query we requested.

For example: if we request the following “AA5” Bing will query for the status of flight number 5 within American Airlines.

If we query Bing for “What does interpolation mean?” It will return the meaning of interpolation as defined in the dictionary.

In order to query Bing for flight information we need to call it with the Airline code and flight number. We are going to pick them up from a simple text box

Please enter flight number: <input type="text" value="AA5" name="searchText" id="searchText" />
<div id="FlightStatusResult">

Let’s use jQuery to get back a JSON result to display:

 function SearchFlightStatus() {
            AppId: "Your App ID",
            Query: $("#searchText").val(),
            Sources: "InstantAnswer",
            Version: "2.2",
            Market: "en-us",
            JsonType: "callback"
        function (data) {
            var errors = data.SearchResponse.Errors;
            if (errors != null) {
            else {

 $(document).ready(function() {         $("#searchText").keypress(function (e) {             if (e.which == 13 && $("#searchText").val() != '') {             SearchFlightStatus();         }     });

If there are any errors we need to show them to the user:

 function DisplayErrors(errors) {
        var resultsHTML = "";
        for (var i = 0; i < errors.length; ++i) {
            for (var errorDetail in errors[i]) {
                resultsHTML+= errorDetail + ": " + errors[i][errorDetail] + "<br />";

Finally if we got back the information we needed we can display it to the user:

 function DisplayResults(data) {
        var resultsHTML = "";
        $.each(data.SearchResponse.InstantAnswer.Results, function (i, item) {
            resultsHTML += "<a href='" + item.Url + "'>" + item.Title + "</a><br>";
            resultsHTML += "Flight: " + item.InstantAnswerSpecificData.FlightStatus.FlightName + "</br>";
            resultsHTML += "Status: " + item.InstantAnswerSpecificData.FlightStatus.StatusString + "</br>";
            resultsHTML += "From: " + item.InstantAnswerSpecificData.FlightStatus.OriginAirport.Name + "</br>";
            resultsHTML += "To: " + item.InstantAnswerSpecificData.FlightStatus.DestinationAirport.Name + "</br>";
            resultsHTML += "Scheduled Departure: " + item.InstantAnswerSpecificData.FlightStatus.ScheduledDeparture + "</br>";
            resultsHTML += "SchedulArrival: " + item.InstantAnswerSpecificData.FlightStatus.ScheduledArrival + "</br>";

The end result will look like this and will contain a link for further flight information.

As you can tell it’s very easy to query Bing and get back useful information for you website or phone. You can view the complete Bing API here

Shout it

Posted 16 Aug 2011 7:34 PM by Gal Ratner
Filed under:

Powered by Community Server (Non-Commercial Edition), by Telligent Systems