QPX Express API with C# 8


Please Share

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.

 

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();

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.

Please Share


Linda Lawton

About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as a developer and a database expert. I have been working with several of the Google APIs, since 2012. I helping others in the On-Line community to develop with the Google APIs, by creating my own blog www.daimto.com. This and my presence on a number of On-Line developer forums lead me to be noticed by the Google Analytics API development team. I was nominated for and recently became one of the first Google Developer Experts for Google Analytics.


Leave a comment

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

8 thoughts on “QPX Express API with C#

  • abe

    hi dear,

    this post is helpful. i implemented it using c# console app. but it is displaying the below error

    Google.Apis.Requests.RequestError
    Bad Request [400]
    Errors [
    Message[Bad Request] Location[ – ] Reason[keyInvalid] Domain[usageLimits]
    ]

    would you please assist me on this.

    Regards

  • Viri

    Hi! I am loving this tutorial, so far the easiest one to connect the QPX API to my wannabe C# Applicaiton. I am a complete beginner for C# currently going trough my first semester. As my final project I need to use the API to be able to get the results. I signed up for one, I installed the Nuget but I am running into assembly issues as apparently the using references I have at the top are not enough. So far I have:
    using Google.Apis.QPXExpress.v1;
    using Google.Apis.Services;
    using Google.Apis.Requests;
    using Newtonsoft.Json;

    However the following errors are marked 🙁 I can’t figure out what using assembly reference I need to enter.

    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();

    Your help would be gladly appreciated.

  • Tan Yih Wei

    Hi. I wish to ask that where should I implement the code above? I already have a project started, installed the API library and get the API key. I stuck on how to start to use the API.