Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HotelBeds Php API providing me empty result

Tags:

php

api

I tried this code to access data but could not able to get.Anyone know how can I add in this file (Xml)

XML file

<availabilityRQ xmlns="http://www.hotelbeds.com/schemas/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<stay checkIn="2015-12-28" checkOut="2015-12-29"/>
 <occupancies>
  <occupancy rooms="1" adults="1" children="1">
   <paxes>
    <pax type="AD" age="31"/>
    <pax type="CH" age="3"/> 
    </paxes>
  </occupancy> 
 </occupancies>
 <hotels>
           <hotel>1067</hotel> 
           <hotel>1070</hotel>
           <hotel>135813</hotel> 
        </hotels> 
</availabilityRQ>

Code to call

The following example requires PHP version greater than 5.5.x and the library pecl_http => 2.5.3 You can install it via https://pecl.php.net

// Your API Key and secret
$apiKey = "6355445214552444";
$sharedSecret = "5456842";

// Signature is generated by SHA256 (Api-Key + Shared Secret + Timestamp (in seconds))
$signature = hash("sha256", $apiKey.$sharedSecret.time());

// Example of call to the API
$endpoint = "https://api.test.hotelbeds.com/hotel-api/1.0/status";

$request = new http\Client\Request("GET",
    $endpoint,
    [ "Api-Key"     => $apiKey,
      "X-Signature" => $signature,
      "Accept"      => "application/xml" ]);
try
{

    $client = new http\Client;

    $client->enqueue($request)->send();



    // pop the last retrieved response

    $response = $client->getResponse();

    if ($response->getResponseCode() != 200) {  

       printf("%s returned '%s' (%d)\n",

           $response->getTransferInfo("effective_url"),

           $response->getInfo(),

           $response->getResponseCode()

       );

    } else {

       printf($response->getBody());

    }

} catch (Exception $ex) {

    printf("Error while sending request, reason: %s\n",$ex->getMessage());

}
?>

can anybody guide me how i call hotel Beds API? where I am making mistake

Thanks

like image 671
Rizwan Gill Avatar asked Dec 23 '15 12:12

Rizwan Gill


2 Answers

I guess you need to POST the xml against the API.

I dont know the API, but given the endpoint is correct, you could try to use a POST request:

$request = new http\Client\Request("POST",
    $endpoint,
    [ "Api-Key"     => $apiKey,
      "X-Signature" => $signature,
      "Accept"      => "application/xml" ],
   $xml);

Where $xml var contains the xml you posted.

like image 113
ivoba Avatar answered Nov 15 '22 17:11

ivoba


The code you show is calling the endpoint

  • HTTP GET https://api.test.hotelbeds.com/hotel-api/1.0/status

whereas the XML you show need to be POST'ed (see that other answer) against

  • HTTP POST https://api.test.hotelbeds.com/hotel-api/1.0/hotels

Please refer to the docs at

  • https://developer.hotelbeds.com/docs/read/apitude_booking/Availability
like image 4
Gordon Avatar answered Nov 15 '22 17:11

Gordon