the following examples are implemented using PHP 7.
Place the proper values to $username, $password, $domain variables.
<?php
ini_set('display_errors', 1);
$headr = array();
$headr[] = 'Content-type: multipart/form-data';
$headr[] = 'Accept:application/json';
$username = "USERNAME";
$password = "PASSWORD";
$domain = "HOTELIGA_DOMAIN";
$token_url = "https://api.hoteliga.com/v1/Token";
$token_data = "grant_type=password&username=".$username."&password=".$password."&domain=".$domain;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $token_data);
$result = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_len);
$body = substr($result, $header_len);
if ($responseCode == '200'){ echo $body; }
else { echo $responseCode; }
?>
Place the proper values to $token and $customer_id variables.
For XML response replace the line
$headr[] = 'Accept: application/json';
with the following:
$headr[] = 'Accept: application/xml';
<?php
ini_set('display_errors', 1);
$token = 'TOKEN';
$customer_id = 'ID';
$headr = array();
$headr[] = 'Accept: application/json';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: Bearer '.$token;
$get_customer_url = "https://api.hoteliga.com/v1/Customer/".$customer_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $get_customer_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_len);
$body = substr($result, $header_len);
if ($responseCode == '200'){ echo $body; }
else { echo $responseCode; }
?>
Place the proper value to $token and the desired data for the new customer.
<?php
ini_set('display_errors', 1);
$token = 'TOKEN';
$create_customer_data_json = array("lastName"=>"Smith",
"firstName"=>"John", "email"=>"johnsmith@example.com");
$headr = array();
$headr[] = 'Accept: application/json';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: Bearer '.$token;
$create_customer_url = "https://api.hoteliga.com/v1/Customer";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $create_customer_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($create_customer_data_json));
$result = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_len);
$body = substr($result, $header_len);
if ($responseCode == '200'){ echo $body; }
else { echo $responseCode; }
?>
<?php
ini_set('display_errors', 1);
$token = 'TOKEN';
$create_customer_data_xml = '<?xml version="1.0" encoding="UTF-8" ?>
<Customer><LastName>Smith</LastName><FirstName>John</FirstName>
<Email>johnsmith@example.com</Email></Customer>';
$headr = array();
$headr[] = 'Accept: application/xml';
$headr[] = 'Content-type: text/xml';
$headr[] = 'Authorization: Bearer '.$token;
$create_customer_url = "https://api.hoteliga.com/v1/Customer";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $create_customer_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $create_customer_data_xml);
$result = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_len);
$body = substr($result, $header_len);
if ($responseCode == '200'){ echo $body; }
else { echo $responseCode; }
?>