Hi, I am new to PHP and am trying to connect to a JSON API where I will retrieve some data from a property booking system. The API provider provides sample code see below, you just add your API Key and Property ID, when the code is loaded you should see the property details in JSON format. I have setup PHP with cURL on a windows server, PHP runs fine but this code will not retrieve any data. Here is the link to the API and sample code. It was a simple copy and paste, I am not getting any errors so I am struggling to debug this. Please could someone look and let me know what is wrong? The API key is to a live test system so you can run this your end. Thanks for looking.
Code:
<?php
/*
* The following sample uses PHP arrays to construct the JSON data and php-curl to post it to the API.
* This sample will get the property information.
* Change the apiKey and propKey to values for your account to use and test.
*/
$authentication = array();
$authentication['apiKey'] = '123456789101112131415167';
$authentication['propKey'] = '99999999999999999';
$data = array();
$data['authentication'] = $authentication;
$json = json_encode($data);
$url = "[URL unfurl="true"]https://api.beds24.com/json/getProperty";[/URL]
$ch=curl_init();
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
curl_setopt($ch, CURLOPT_VERBOSE, true);
if (!curl_errno($ch)) { // $ch (curl resource) instead of $url (string)
$info = curl_getinfo($ch);
echo 'Took ', $info['total_time'], ' seconds to send a request to ', $info['url'], "\n";
}
curl_close ($ch);
echo $result;
?>