2

Currently using a test developer account for Sabre Dev Studio and trying to use their REST Api - Instaflights_Search.

I'm creating the authentication and getting an access token fine but the problem arises when I try to send a request. I'm creating the headers using curl and php.

function callRestApi($url,$access_token) {

    $ch = curl_init();

    $header = array();
    $header[] = "Authorization: Bearer " .$access_token;
    $header[] = "Accept: application/json";
    $header[] =  'Content-Type: application/json';

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_HTTPGET, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result,true);
}


$url = "https://api.test.sabre.com/v1/shop/flights?origin=JFK&destination=LAX&departuredate=2016-05-30&returndate=2016-05-31";

$access_token = callForToken();

$server_response = callRestApi($url,$access_token);

The Sabre response is:

   array(5) {
     ["status"]=>
     string(12) "NotProcessed"
     ["type"]=>
     string(10) "Validation"
     ["errorCode"]=>
     string(30) "ERR.2SG.CLIENT.INVALID_REQUEST"
     ["timeStamp"]=>
     string(29) "2016-05-19T22:36:51.041-05:00"
     ["message"]=>
     string(60) "Request is invalid: The request should have the JSON payload"
    }

And the HTTP 1/1 request header reads as:

* Hostname was found in DNS cache
*   Trying 151.193.52.94...
* Connected to api.test.sabre.com (151.193.52.94) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
* SSL connection using TLSv1.2 / AES256-SHA
* Server certificate:
*    subject: C=US; ST=Texas; L=Southlake; O=Sabre, Inc.; OU=Internet   Services; CN=api.test.sabre.com
*    start date: 2015-02-25 00:00:00 GMT
*    expire date: 2017-03-21 23:59:59 GMT
*    subjectAltName: api.test.sabre.com matched
*    issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4
*    SSL certificate verify ok.
    > GET /v1/shop/flights?origin=JFK&destination=LAX&departuredate=2016-05-30&returndate=2016-05-05&onlineitinerariesonly=n&limit=10&offset=1&eticketsonly=n&sortby=totalfare&order=asc&sortby2=departuretime&order2=asc&pointofsalecountry=US HTTP/1.1
Host: api.test.sabre.com
Authorization: Bearer T1FNEWIhYyxjzQJ/Fh4oPfgkjU4s+R/xAxglSqD2oC4kYcCAnPcIv+bbV9sTu3KHxdpQ+zRKUsTGmpfhQT//Djx+3yDNZUcypKrbjzIzjVJvDPI+PyH5bT4F88Gcse//7hjcrz5sCRXkqwqjb1ceaBhGV2hr0t47XwBcjEvPg2I92FtFsqNw7V8NrcPfBVFxnZAbqESJ+zUQH6mSeaWa1h3Rc04g4szipQhHWDnR+sneH8ePdHKPQaoX3M44YMRvviOV8yEBYwTg**
Accept: application/json
Content-Type: application/json

< HTTP/1.1 400 Bad Request
< Date: Fri, 20 May 2016 03:15:28 GMT
< Content-Type: application/json
< Content-Length: 207
< 
* Connection #0 to host api.test.sabre.com left intact

Any ideas what could be the problem with the header?

EDIT at 23/05/2016 Corrected version for building the request header below:

     function callRestApi($url,$access_token) {

      $header2 = array(
      'Authorization : Bearer '.$access_token,
      'Accept : */*'
      );

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
      curl_setopt($ch, CURLOPT_VERBOSE, true);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $header2);
      $result = curl_exec($ch);
      curl_close($ch);
      return json_decode($result,true);
   }
Sandi B
  • 23
  • 4
  • 1
    Have you tried to make the request with another method/program/framework just to check if the request is ok? Maybe trying with postman or something like that... Came here fron DevRant haha – PekosoG May 20 '16 at 05:12
  • devRant making the world a better place one disgruntled rant at a time :) Thanks for the suggestion, I'll try that and let you know how it goes! – Sandi B May 20 '16 at 13:17

2 Answers2

1

have you looked at the php sample code from Sabre github repo?

https://github.com/SabreDevStudio/SACS-Php

It's using IntaFlights and curl, so maybe it provides an approach to the API you are testing and your environment.

Feel free to add an issue if not working for you.

fcarreno
  • 701
  • 4
  • 8
  • Thanks for guiding me to their github project. I was able to use the function where they were building their header and the problem seems to have been with my curl_setopt. I've posted the corrected version in the original question for anyone interested. Thanks again! – Sandi B May 24 '16 at 02:29
0

Well, I notice two things off the bat that may point you in the right direction:

  1. The error message in the Sabre response mentions that a JSON payload is missing. Are you purposefully omitting data as part of your request? (Some services are written poorly and expect a body, even if it's empty ("{ }").)
  2. Perhaps their API is broken? If you look at the HTTP request (in your second block), notice how the URL changed? The return date variable specified isn't even valid (you supplied "2016-05-31" and it changed (auto redirect?) to "2016-05-315". That is, unless you copy/pasted from two different requests.

Hope this helps.

Martin
  • 21
  • 4
  • 1, Not purposefully omitting data. Made sure to include all the required fields so I'm not sure why I'm getting the JSON payload missing response. 2. Sorry about that, the date issue was a typo from copy & paste, didn't realise it was in my post until you pointed it out. (Also just edited the post to remove it to not confuse anyone else.) For the most part, their API doesn't seem to be broken because it works on their test servers and in the apps on their demo gallery. Thanks again for taking the time to respond! – Sandi B May 20 '16 at 12:06
  • Gotcha. In that case, I would suggest the same as Pekoso said above - try creating the request in another tool (e.g. Postman), and see if you experience the same issue. – Martin May 20 '16 at 12:23