QPX Express API with C# 19


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 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 *

19 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.

  • Vishwa

    Hi, Thank you so much for the in-detail tutorial. I couldn’t find another well documented one like this. I managed to retrieve data from the QPX Express API successfully. But there is a result difference between their demo (https://qpx-express-demo.itasoftware.com/) and the results that I’m printing to the Console. Specially there is a huge price difference. Really appreciate if you could help me with this.

    Thanks in advance.

  • rohit

    I use same code but give error:

    An exception of type ‘Google.GoogleApiException’ occurred in Google.Apis.dll but was not handled in user code

    Additional information: Google.Apis.Requests.RequestError

    Access Not Configured. QPX Express API has not been used in project 542044161740 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/qpxExpress.googleapis.com/overview?project=542044161740 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. [403]

    Errors [

    Message[Access Not Configured. QPX Express API has not been used in project 542044161740 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/qpxExpress.googleapis.com/overview?project=542044161740 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.] Location[ - ] Reason[accessNotConfigured] Domain[usageLimits]

    ]

    • rohit

      My Code
      x.Request.Slice.Add(new SliceInput()
      {
      Origin = model.Origin,
      Destination = model.Destination,
      Date = model.CheckInDate.ToString()
      });
      x.Request.Slice.Add(new SliceInput()
      {
      Origin = model.Destination,
      Destination = model.Origin,
      Date = model.CheckOutDate.ToString()
      });