The online service "eTermin" provides an API Url which outputs reviews of my service.
I tried it with this code but only got a bad request and an error:
$service_url = 'https://www.etermin.net/api/rating/';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false); // DEBUGGING set to true
$curl_response = curl_exec($curl);
echo print_r($curl_response); // test the JSON array
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response, true);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
The eTermin FAQ did not provide all the information needed. In order to GET or POST you need to send a publickey, a salt and an encoded signature in the Header.
So this is the solution to GET the ratings of my eTermin account (the return is not formatted yet!):
$publicKey = "[publicKey]";
$secretKey = "[secretKey]";
// Generates a random string of ten digits
$salt = mt_rand();
// Computes the signature by hashing the salt with the secret key as the key
$signature = hash_hmac('sha256', $salt, $secretKey, true);
// base64 encode
$encodedSignature = base64_encode($signature);
// CURL GET REQUEST
$service_url = 'https://www.etermin.net/api/rating/';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'publickey:'.$publicKey,
'salt:'.$salt,
'signature:'.$encodedSignature
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_HEADER, true);
$curl_response = curl_exec($curl);
$curl_response = json_decode($curl_response);
echo print_r($curl_response);
This is what it returns:
Array ( [0] => stdClass Object ( [ID] => 60979 [AppointmentExternalID] => XXXXXXX [CustomerFeedback] => Sehr schöner Laden, sehr privat. Wir wurden von zwei Experten gleichzeitig beraten, Preise sind angemessen. Schöne Anzüge. Wir sind zufrieden. [Rating] => 5 [CustomerInfo] => Benjamin (email@something.at, ) [RatingDate] => 2018-01-24T17:21:20.793 [CalendarID] => 46499 [CalendarName] => Kalender [ServiceID] => 60347 [Publish] => 1 ) [1] => stdClass Object ( [ID] => 61014 [AppointmentExternalID] => XXXXXXXX [CustomerFeedback] => [Rating] => 5 .....
Now all I need to do is format this somehow and get the char encoding to work.
In order to parse the JSON for eTermin ratings use this foreach loop:
//Traverse array __standard_Obj
foreach ($decoded as $key => $value) {
$c_feeback = $value["CustomerFeedback"];
$c_name = $value["CustomerInfo"];
$c_name = before ('(',$c_name);
$c_rating = $value["Rating"];
$c_date = $value["RatingDate"];
if(!empty($c_feeback)):
echo '<h2>Feedback:'.$x.'</h2>';
$x++;
echo '<div>';
if(strlen($c_name)>3):
echo $c_name;
else:
echo "Anonym";
endif;
echo ': '.$c_feeback;
//positiv stars
//$c_rating = 4; //testvalue
for($c = 0; $c < $c_rating; $c++) {
echo '<span class="fa fa-star checked"></span>';
}
//negative stars
$c_rating = 5 - $c_rating;
for($c = 0; $c < $c_rating; $c++) {
echo '<span class="fa fa-star"></span>';
}
endif;
}