Inhalt
Mit der REST API des apt-shop können Sie den Shop fremdsteuern. Sie können sämtliche Daten abrufen, ändern oder hinzufügen. Sie haben somit die Möglichkeit, den Shop mit Anwendungen von Drittanbietern zu verknüpfen.
Verfügbare Ressourcen
Ressource | GET | POST | PUT | DELETE |
---|---|---|---|---|
Products | ja | nein | ja | nein |
ProductsStock | ja | nein | ja | nein |
Orders | ja | ja | ja | nein |
Baskets | nein | ja | ja | ja |
Customers | ja | ja | ja | nein |
Bills | ja | nein | ja | nein |
NewsletterRecipients | ja | nein | nein | nein |
Generierung der API Key
Unter Einstellungen -> Grundkonfiguration -> API können Sie Ihre API-Keys verwalten und neue hinzufügen. Wählen Sie für jeden API-Key ein eigenes hashToken, das für die Erstellung der Signature benötigt wird. Geben Sie ebenso an, welche Operationen für diesen API-Benutzer erlaubt sind.
Standard Rückgabe
Es wird ein json-codiertes Array zurückgeben mit folgenden Werten:
Parameter | Wert | Beschreibung |
---|---|---|
status | success/error/warning | Ein String über den Erfolg des Requests |
warnings | string (optional) | Hinweise, ob eine Warnung aufgetreten ist |
errors | string (optional) | Hinweise, die den Fehler beschreiben |
data | array | die ressourcenspezifischen Daten |
Beispiel Client Klasse
//API Client Test class APIClient { private $api_key; private $api_hash; private $api_url; private $httpcode; public function __construct($api_url,$api_key,$api_hash) { $this->api_url=$api_url; $this->api_key=$api_key; $this->api_hash=$api_hash; } /*Function to send HTTP POST Requests*/ public function sendRequest($url, $method='GET', $data=array(),$params=array()){ $urlparams = http_build_query($params); $request_url = $this->api_url.$url; if(strpos($url,'?')===false) $request_url.='?'.$urlparams; else $request_url.='&'.$urlparams; $urldata=explode('?',$url); $headers=array( 'Content-Type: application/json; charset=utf-8', 'Apt-Api-Key: '. $this->api_key, 'Apt-Api-Signature: '.$this->createSignature($urldata[0], $method) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $this->httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if(!$response){ return false; } return json_decode($response,true); } public function get($url, $params = array()) { return $this->sendRequest($url, 'GET', array(), $params); } //create public function post($url, $data = array(), $params = array()) { return $this->sendRequest($url, 'POST', $data, $params); } //update public function put($url, $data = array(), $params = array()) { return $this->sendRequest($url, 'PUT', $data, $params); } public function delete($url, $params = array()) { return $this->sendRequest($url, 'DELETE', array(), $params); } private function createSignature($url,$method) { return md5($url.$method.$this->api_hash); } } $api_key = 'mein_API_KEy'; $api_hash = 'mein_HASH_Token'; $api_url = 'https://www.example.de/api/v1/'; $t = new APICLient($api_url,$api_key,$api_hash); //example to get the product width id 1 $result=$t->get('Products/1');