Reputation: 23
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);
}
Upvotes: 2
Views: 2261
Reputation: 701
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.
Upvotes: 1
Reputation: 21
Well, I notice two things off the bat that may point you in the right direction:
Hope this helps.
Upvotes: 0