Über diese API lassen sich alle Produktinformationen eines bestimmten Produktes abrufen.
Weiter ist zu sehen, wie auf Bilder und PDF Informationen zugegriffen werden kann.
<pre class="wp-block-syntaxhighlighter-code"><?php
// VARIABLES
$access_token = '1234567890';
// FOR DEMO PURPOSE FIX PRODUCT ID
$id_product = 566;
$api_url = 'https://api.ixxilon-apothekenservice.de';
$api_url_product_detail = $api_url.'/api/products/'.$id_product;
// API HEADERS
$headers = [];
$headers[] = 'Accept: application/ld+json';<br />$headers[] = 'Content-Type: application/json';
$headers[] = "X-AUTH-TOKEN: $access_token";
/**
* PRODUCT DETAIL
*/
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $api_url_product_detail);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// GET API RESPONSE
if ($response = curl_exec($curl)) {
// JSON DECODE
$product_detail = json_decode($response);
// OUTPUT ID and TEXT1
echo 'id_product: '.$product_detail->id.'<br>';
if ($product_detail->text1!=='') {
#echo 'text1 :'.$product_detail->text1.'<br>';
}
// CHECK IF OTHER TEXT ELEMENTS ARE SET
if ($product_detail->text2!=='') {
echo 'text2 :'.$product_detail->text2.'<br>';
}
if ($product_detail->text3!=='') {
echo 'text3 :'.$product_detail->text3.'<br>';
}
if ($product_detail->text4!=='') {
echo 'text4 :'.$product_detail->text4.'<br>';
}
if ($product_detail->text5!=='') {
echo 'text5 :'.$product_detail->text5.'<br>';
}
/**
* PRODUCT IMAGE
*/
// GET IMAGES (1-8)
for ($i=1; $i<=8; $i++) {
// DYNAMIC OBJECT FIELD
$image_field = "image".$i;
// IMAGE SIZE
$image_width = 2000;
if ( $product_detail->{$image_field}!==NULL ) {
// SHOW IMAGE FIELD
echo 'image '.$i.' :'.$product_detail->{$image_field}.'<br>';
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl2, CURLOPT_URL, $api_url . $product_detail->{$image_field} . '?width='.$image_width);
curl_setopt($curl2, CURLOPT_HTTPHEADER, $headers);
if ($response = curl_exec($curl2)) {
// SAVE DATA TO FILESYSTEM
$status = file_put_contents($id_product.'-image-'.$i.'.jpg', $response);
}
#var_dump(curl_error($curl2));
#var_dump('Code: ' . curl_errno($curl2));
curl_close($curl2);
}
}
/**
* PRODUCT PDF
*/
// GET PDF (1-3)
for ($i=1; $i<=3; $i++) {
// DYNAMICH OBJECT FIELD
$pdf_field = "pdf" . $i;
if ( $product_detail->{$pdf_field}!==NULL ) {
echo 'pdf'.$i.' :' . $product_detail->{$pdf_field} . '<br>';
$curl3 = curl_init();
curl_setopt($curl3, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl3, CURLOPT_URL, $api_url . $product_detail->{$pdf_field});
curl_setopt($curl3, CURLOPT_HTTPHEADER, $headers);
if ($response = curl_exec($curl3)) {
// SAVE DATA TO FILESYSTEM
$status = file_put_contents($id_product.'-pdf-'.$i.'.pdf', $response);
}
curl_close($curl3);
}
}
}
else {
// CHECK IF IS CURL / API ERROR
var_dump(curl_error($curl));
var_dump('Code: ' . curl_errno($curl));
}
curl_close($curl);</pre>