QPX Express API with C# 21


WARNING: The QPX Express API service ended on April 10, 2018. See below for more information. I am leaving this tutorial her for archive purposes only.

QPX Express is a new, simplified airfare search API that offers basic shopping capabilities. It allows easy access to air travel search via a single, standardized API. The QPX Express self-service, pay-as-you-go model provides business flexibility and offers new opportunities for innovation. We as developers can now create some inserting applications using Flight data. In this short tutorial I am going to show you how to access public flight data using the Google APIs .net client library.

[wp_ad_camp_3]

Prerequisites

  1. Create public API key credentials on the Google Developers console. If you don’t know how to do that please read Google Developer Console Create Public API Key
  2. Install nuget package.Install-Package Google.Apis.QpxExpress.v1

Authentcate

QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer()
     {
     ApiKey = "Your API KEY",
     ApplicationName = "Daimto QPX Express Sample",
     });

Requesting flight data

There is quite a lot that you can search on with the QPX API. I sugest that you check out the documentation. There isn’t a lot there right now but by checking the request parameters you can get an idea of what you could search on.

            TripsSearchRequest x = new TripsSearchRequest();
            x.Request = new TripOptionsRequest();
            x.Request.Passengers = new PassengerCounts { AdultCount = 2 };
            x.Request.Slice = new List();
            x.Request.Slice.Add(new SliceInput() { Origin = "JFK", Destination = "BOS", Date = "2015-10-29" });
            x.Request.Solutions = 10;
            var result = service.Trips.Search(x).Execute();

[wp_ad_camp_5]

Displaying flight data

Once we get our data back there is a lot of information we can dig though here is just a quick idea of what we can see.

 // Aircraft
            foreach (var aircraft in result.Trips.Data.Aircraft)
            {

                Console.WriteLine(aircraft.Name + aircraft.Code);

            }

            // Airport
            foreach (var airport in result.Trips.Data.Airport)
            {
                Console.WriteLine(airport.Name + " - " + airport.City);
            }
            foreach (var carrier in result.Trips.Data.Carrier)
            {
                Console.WriteLine(carrier.Name);
            }


            foreach (var trip in result.Trips.TripOption)
            {

                Console.WriteLine("Flight Number: " + trip.Slice.FirstOrDefault().Segment.FirstOrDefault().Flight.Number);
                Console.WriteLine("    Duration: " + trip.Slice.FirstOrDefault().Duration);
                Console.WriteLine("     Cabin: " + trip.Slice.FirstOrDefault().Segment.FirstOrDefault().Cabin);
                Console.WriteLine("   price: " + trip.Pricing.FirstOrDefault().BaseFareTotal.ToString());
            }

Conclusion

The QPX Express API is a public API which means that we can use an public API key to access flight data. This was just a quick post to help someone on stackoverflow get the idea.

If you create any interesting apps with the QPX API I would really like to hear about it.


About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

21 thoughts on “QPX Express API with C#