Rizwan Gill
Rizwan Gill

Reputation: 2253

HotelBeds Php API providing me empty result

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

Upvotes: 10

Views: 2420

Answers (3)

Manoj Sharma
Manoj Sharma

Reputation: 1

You are using endpoint which is used for checking the status of api.

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

You need to call below endpoints for getting the live availability of hotels

https://api.test.hotelbeds.com/hotel-api/{version}/{operation}

Upvotes: 0

Gordon
Gordon

Reputation: 316999

The code you show is calling the endpoint

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

Please refer to the docs at

Upvotes: 4

ivoba
ivoba

Reputation: 5986

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.

Upvotes: 4

Related Questions