ixxilon Apothekenservice
Die api zur product-list

 

Das Code-Beispiel für den Zugriff auf die IXXILON-API

Über diese API können alle Produkte abgerufen werden. Dieser Abruf liefert zu allen Produkten nur die Produkt ID. In einem separaten Abruf (Link unter dem Code-Bsp.) werden dann alle Produktinformationen abgerufen.

<?php
$access_token = 'YOURACCESSTOKENXX123';
$api_url_product_list = 'https://api.ixxilon-apothekenservice.de/api/products?pagination=false';

$headers = [];
$headers[] = 'Accept: application/ld+json';
$headers[] = 'Content-Type: application/json';
$headers[] = "X-AUTH-TOKEN: $access_token";


/**
 * RETRIEVE PRODUCT LIST
 */
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $api_url_product_list);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

// GET API RESPONSE
if ($response = curl_exec($curl)) {
    // JSON DECODE API RETURNED OBJECT
    $response = json_decode($response);

    // ITERATE LIST
    if (count($response->data)>0) {
        foreach($response->data as $item) {
            echo 'API URL Product detail: '.$item->id.'<br>';
            echo 'ID Product: '.$item->attributes->_id.'<br>';
        }
    }

}
else {
    // CHECK IF IS CURL / API ERROR
    var_dump(curl_error($curl));
    var_dump('Code: ' . curl_errno($curl));
}
curl_close($curl);

Die API liefert ein Ergebnisobjekt zurück, welches aus Links, Meta und Data besteht.
Links: diese Links können für die Pagination genutzt werden und zeigen jederzeit an, wo man sich befindet und weiter „gehen“ kann.
Meta: dient als Hilfe, um zu sehen wieviele Produkte abrufbar sind
Data: ist ein Array Element, dass maximal 30 Elemente pro Durchlauf beinhaltet

&lt;?php 
/* START
[links] =&gt; stdClass Object
        (
            [self] =&gt; /api/products?page=1
            [first] =&gt; /api/products?page=1
            [last] =&gt; /api/products?page=8420
            [next] =&gt; /api/products?page=2
        )

[meta] =&gt; stdClass Object
        (
            [totalItems] =&gt; 252589
            [itemsPerPage] =&gt; 30
            [currentPage] =&gt; 1
        )
[data] =&gt; Array
        (
            [0] =&gt; stdClass Object
                (
                    [id] =&gt; /api/products/3001879
                    [type] =&gt; Product
                    [attributes] =&gt; stdClass Object
                        (
                            [_id] =&gt; 3001879
                        )

                )

            [1] =&gt; stdClass Object
*/

/* BEISPIEL PAGE 1000
[links] =&gt; stdClass Object
        (
            [self] =&gt; /api/products?page=1000
            [first] =&gt; /api/products?page=1
            [last] =&gt; /api/products?page=8420
            [prev] =&gt; /api/products?page=999
            [next] =&gt; /api/products?page=1001
        )
*/

?&gt;

Hier geht es zum Code-Beispiel für den separaten Abruf.