Webhook
API endpoint: /webhook
Defined events:
-
order.create
- order has been created -
order.edit
- order has been modified (e.g. change of status) -
order.delete
- order has been deleted -
order.cancel
- order has been cancelled
All Webhooks created by plugins have an X-Webareal-Signature
header with an eshop identifier value (eshopCode).
The structure of the incoming Webhooks can be found at this address: https://helpdesk.webareal.cz/article-base/webareal-webhook-api-dokumentace (czech only)
Please note that the X-Webareal-Signature
header mentioned in the article, in the case of plugins, contains an eshop identifier (eshopCode), not a unique signature generated in the eshop administration.
Creating a webhook
POST /webhook
{ "name": "plugin-webhook", "url": "https://plugin.tld/webhook", "isEnabled": true, "event": "order.create" }
Example:
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.webareal.cz/webhook', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode([ 'name' => "plugin-webhook", 'url' => "https://plugin.tld/webhook", 'isEnabled' => true, 'event' => "order.create" ]), CURLOPT_HTTPHEADER => array( 'X-Wa-api-token: ' . $api_token, // apiToken získáte při instalaci doplňku, viz. nápověda 'Authorization: Bearer ' . $bearer, // access token získáte zde, údaje zde (záložka API přístup) 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
Webhook update
PUT /webhook/{id}
{ "url": "https://plugin.tld/webhook", "isEnabled": true, }
Example:
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.webareal.cz/webhook/{id}', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => json_encode([ 'name' => "plugin-webhook2", 'url' => "https://plugin.tld/webhook" ], CURLOPT_HTTPHEADER => array( 'X-Wa-api-token: ' . $api_token, // apiToken získáte při instalaci doplňku, viz. nápověda 'Authorization: Bearer ' . $bearer, // access token získáte zde, údaje zde (záložka API přístup) 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
Removing webhook
DELETE /webhook/{id}
Example:
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.webareal.cz/webhook/{id}', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_HTTPHEADER => array( 'X-Wa-api-token: ' . $api_token, // apiToken získáte při instalaci doplňku, viz. nápověda 'Authorization: Bearer ' . $bearer, // access token získáte zde, údaje zde (záložka API přístup) 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;