Expedia PHP SimpleXML API code
Hi, Today i am going to share how to retrieve datas from XML using expedia API sandbox. Here you find Expedia API Tester,
http://devhub.ean.com/apitester/index.html
You can use any queries based on your requirement. Then you have to process the query. Once done, you will get API link using this link you can retrieve Array in PHP. Here you go,
<?php
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$api_key = '***********';
$url = 'http://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55505&minorRev=150&apiKey='.$api_key.'&locale=en_US¤cyCode=USD&xml=<HotelListRequest><city>Seattle</city><stateProvinceCode>WA</stateProvinceCode><countryCode>US</countryCode><arrivalDate>2/16/2014</arrivalDate><departureDate>2/18/2014</departureDate><RoomGroup><Room><numberOfAdults>2</numberOfAdults></Room></RoomGroup><numberOfResults>25</numberOfResults></HotelListRequest> ';
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
print "<pre>";
print_r($xml);
?>
The Output will be in this format,
http://devhub.ean.com/apitester/index.html
You can use any queries based on your requirement. Then you have to process the query. Once done, you will get API link using this link you can retrieve Array in PHP. Here you go,
<?php
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$api_key = '***********';
$url = 'http://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55505&minorRev=150&apiKey='.$api_key.'&locale=en_US¤cyCode=USD&xml=<HotelListRequest><city>Seattle</city><stateProvinceCode>WA</stateProvinceCode><countryCode>US</countryCode><arrivalDate>2/16/2014</arrivalDate><departureDate>2/18/2014</departureDate><RoomGroup><Room><numberOfAdults>2</numberOfAdults></Room></RoomGroup><numberOfResults>25</numberOfResults></HotelListRequest> ';
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
print "<pre>";
print_r($xml);
?>
The Output will be in this format,
SimpleXMLElement Object
(
[customerSessionId] => 0ABAAA8C-6F7B-6914-39F2-7EB59990125E
[numberOfRoomsRequested] => 1
[moreResultsAvailable] => true
[cacheKey] => -96f7b6:1439f7eb599:-1109
[cacheLocation] => 10.186.170.140:7300
[cachedSupplierResponse] => SimpleXMLElement Object
(
[@attributes] => Array
(
[supplierCacheTolerance] => NOT_SUPPORTED
[cachedTime] => 0
[supplierRequestNum] => 204
[supplierResponseNum] => 25
[supplierResponseTime] => 741
[candidatePreptime] => 34
[otherOverheadTime] => 12
[tpidUsed] => 5001
[matchedCurrency] => true
[matchedLocale] => true
)
)
[HotelList] => SimpleXMLElement Object
(
[@attributes] => Array
(
[size] => 25
[activePropertyCount] => 226
)
[HotelSummary] => Array
(
[0] => SimpleXMLElement Object
(
and so on.....
Comments
Post a Comment