QPX Express API - Flight list

Asked

Viewed 253 times

0

I’m trying to use the QPX Express API to search for flight lists, the documentation has how to pass the arguments, but I do not know how to use, for example:

Documentation:

The simplest way to Try out this API is to send it a POST request with Curl. For >example, create a file named request.json with the following content (replace each >instance of YYYY-MM-DD with a date, which can be up to a year in the Future.):

JSON:

{
  "request": {
    "passengers": {
      "adultCount": 1
    },
    "slice": [
      {
        "origin": "BOS",
        "destination": "LAX",
        "date": "YYYY-MM-DD"
      },
      {
        "origin": "LAX",
        "destination": "BOS",
        "date": "YYYY-MM-DD"
      }
    ]
  }
}

The documentation says so:

Then execute the following command from Within the same directory as the above >request.json file. (As Explained in Prerequisites, you must first obtain an API key.)

Curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=your_API_key_here

Where to run this code?

2 answers

1


SOLUTION

I managed after a lot of research to get the flight list using qpxExpress

<?php 

$url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=SUA-API-KEY";
$data_string = '{
                  "request": {
                    "passengers": {
                      "adultCount": 1
                    },
                    "slice": [
                      {
                        "origin": "MCO",
                        "destination": "GRU",
                        "date": "2015-01-23"
                      }
                    ],
                    "solutions": 2
                  }
                }';                                                                            
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                                   

$result = curl_exec($ch); // resultado!!!!
?>

thank you!

0

Basically to test the QPX Express API using Curl you should follow these steps:

  1. Create a JSON file named request.json with the content you put in the question and save in a place you remember later, remembering that the documentation asks you to change the date:

In my case I put the one-way date to (20 January 2015) and the date back to (27 January 2015)

request json

  1. Access via terminal/prompt the location where you saved the created file and run the:

Curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=sua-API-Key

curl

  1. As a response you will see in the terminal a JSON code with a lot of information about the flight, follows excerpt from the API response:

response


Considerations:

  • but how can I get this data in json

  • have how I do using PHP?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.