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
- 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
- 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.
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
did you enable the QPX API in the Google developers console?
i enabled, now it is working thank you
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.
Welcome to the world of C#, if you are using visual studio you can right click the offending method and it should help you add the proper reference.
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.
You dont start an API the API is always running on Googles Servers. You just need to read from it.
For your information, I am using Visual Studio 2015 Community and ASP.NET. Thanks
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.
Hi Linda Lawton!
I can download this example where? Pls send for me a link.
Thank’s and best regards!
Most of my samples live in the project on github Qpx express
Dear Linda Lawton!
Pls review link again. It not exist.
which preview link?
This is link:
https://github.com/LindaLawton/Google-Dotnet-Samples/tree/master/QPX%20Express%20API/v1.
It show Page not found.
try this i have reorganised that project https://github.com/LindaLawton/Google-Dotnet-Samples/tree/master/Samples/QPX%20Express%20API
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]
]
When you created our project in Google Developer console you for got to enable the API. Go and enable it. It should only take five minutes.
Can you please help with this Error
Google.GoogleApiException: ‘An Error occurred, but the error response could not be deserialized’
Inner Exception
JsonReaderException: Error parsing NaN value. Path ”, line 1, position 1.
the [QPX express api](https://developers.google.com/qpx-express/) is discontinued. the only help i can give you is find another api. I dont know of any.
this code for ONEWAY i new two way ho to use this code
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()
});