So I'm working on expedia's API, and have successfully worked many of the API requests but am unable to get just one to work though I've tried and searched in vain for what could be the problem.
My Function looks like this:
global $cid, $apiKey, $sig, $minor_rev;
$url= 'http://api.ean.com/ean-services/rs/hotel/v3/paymentInfo?minorRev='.$minor_rev.'';
$url .= '&cid='.$cid.'';
$url .= '&sig='.$sig.'';
$url .= '&apiKey='.$apiKey.'';
$url .= '&customerUserAgent='.$PaymentTypeData['customerUserAgent'].'';
$url .= '&customerIpAddress='.$PaymentTypeData['customerIpAddress'].'';
$url .= '&customerSessionId='.$PaymentTypeData['customerSessionId'].'';
$url .= '&locale=en_US&_type=json';
$url .= '&currencyCode='.$PaymentTypeData['currencyCode'].'';
$url .= '&hotelId='.$PaymentTypeData['hotelId'].'';
$url .= '&supplierType=E';
$url .= '&rateType=MerchantStandard';
$header[] = "Accept: application/json";
$header[] = "Accept-Encoding: gzip, deflate";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = json_decode(curl_exec($ch), true);
$HotelPaymentResponse = array();
$HotelPaymentResponse[] = $result['HotelPaymentResponse'];
echo '<pre>';
echo $url;
print_r($result);
echo '<h1>GET HOTEL PAYMENT TYPES</h1>';
print_r($HotelPaymentResponse);
echo '</pre>';
return $HotelPaymentResponse;
When I echo the URL and try it in the browser the result is as expected, an array of the payment types in json form.... but for the life of me getting this into the php array for the return eludes me.
Here is a link to the API spec: http://developer.ean.com/docs/payment-types/
And yes I have checked out JSON guides often posted on S.Overflow....
any help would be so very appreciated...
PS:
the API says the repose will look like:
{
"HotelPaymentResponse": {
"@size": "4",
"@currencyCode": "USD",
"customerSessionId": "0ABAAAC9-9A32-7914-9E32-D7EC7F906769",
"PaymentType": [
{
"code": "AX",
"name": "American Express"
},
{
"code": "DS",
"name": "Discover"
},
{
"code": "CA",
"name": "Master Card"
},
{
"code": "VI",
"name": "Visa"
}
]
}
}
BUT my Array is returning:
Array
(
[0] =>
)
SOLVED:
Thanks to working through the comments below and researching the error thrown, 505 - I googled and found someone say they had an error because of a stray space in the url. My error was because my Customer user agent was populating from php's user HTTP agent... Removed that and manually entered and now I can curl the response.
echo $url; print_r($result);What does that show?