Searching best tickets to Europe: API testing and development I

Apibot
4 min readSep 8, 2017

--

This article is the second of a series related to API testing.

I will take advantage of Google QPX Express API and Apibot, to retrieve the best fares to travel to Europe, this will be just an example of how you could use Apibot and APIs to get some useful information.

The document will be as follow. First, we will explain Google QPX Express. Second, we will describe POST method on REST architecture. And finally, we will show you how to implement the example and get the expected results.

Google QPX Express

Google QPX Express provides you to obtain global flight search and pricing in a single, standard API. Right now, the API has only one method which is a POST method with the REST architecture.

The method is to search for a list of flights that meets the specified parameters.

Take a look at their webpage if you want to know more about Google QPX Express

POST

You use the POST method to create (or add data), creating a subordinate entity to some other resource. If the addition of data is successful, it returns an HTTP status code of 201 (OK), as well as sending the location header with a link to the newly-created resource.

In the following example, we will be requesting a list of flights with a POST method, and get what the cheapest city to fly to from New York City to Europe.

EXAMPLE

First, we need to understand the reference for the method we will be using, which is the Trips: Search. On this example, we will be using four (4) main (parents) property, which are:

  • Slice: Containing the origin, destination and date
  • Passengers: On this case it is a search for 1 adult
  • Solutions: the number of results, we selected 20.
  • Refundable: as is false. Right now we don’t care if it is refundable

By looking at the document, we must provide the key as a parameter, of the query, and the URL.

After understanding, we go to Apibot and start building our new graph. First, we will create the configuration node, to add the needed variables that we will be applying to our scenario.

Given that we want to know what city is the cheapest to flight to from NYC to Europe, we will use one of Apibot greatest functionality, which is the use of CSV to upload different data variables to test our scenario. For this case, we will use the following variables:

  • URL: The url where our endpoints are located
  • key: the App key provided by Google to use their API
  • origin: Airport or city IATA designator of the origin
  • destination: Airport or city IATA designator of the destination
  • date: Departure date YYYY-MM-DD format

First, we will create our configuration, with the first two variables (URL and Key).

Configuration node for QPX Express

For the other variables, we need to create a CSV file containing on the first row the variable names (Origin, Destination, Date), and on the next rows the value. As presented in the following excel file:

variables on CSV file

After doing the CSV file, we will use the CSV node to add the displayed variables.

CSV for Multiple variables

Then we will add the HTTP Request node for the POST Method, using the endpoint for the URL field:

 https://www.googleapis.com/qpxExpress/v1/trips/search, 

when using our variable it ends up being

${url}/trips/search

And inserting our key variable as shown on the image below (HTTP Request with the POST method). We change the method to POST, and add a Header with the key value and name:

  • content-type = application/json

For the body, we write the properties that apply to this method, which as shown before are the slice, passengers, solutions and refundable, in our case our JSON will be as follows:

{
"request": {
"slice": [
{
"origin": "${origin}",
"destination": "${destination}",
"date": "${date}"
}
],
"passengers": {
"adultCount": 1,
"infantInLapCount": 0,
"infantInSeatCount": 0,
"childCount": 0,
"seniorCount": 0
},
"solutions": 20,
"refundable": false
}
}

The graph ends up being as follows.

HTTP Request with the POST method

With this, we can execute the graph, and obtain the results of the different fare prices for each airline. Nonetheless, the result ‘s hard to read, because you have to read line by line to see the total price of the ticket. On the next chapter, we will be using another function of Apibot to be able to facilitate the lecture.

Follow us! and start using Apibot for your API test and development 😀

--

--

Apibot

Automate integration tests fast and easy. It will take you less time than reading these lines 😀