Webhooks ======== Webhooks are used for sending data to a URL when an event happens in *Fast Events*. An example event is when a new order is added, updated, deleted, ... .. contents:: Table of contents :local: :backlinks: none :depth: 3 ---- How does it work? ----------------- Action scheduler ~~~~~~~~~~~~~~~~ *Fast Events* uses the `Action scheduler `_, which is widely used by other WordPress plugins including `Woocommerce `_. *Fast Events* uses it for Webhooks, email retries and RSVP events if confirmation emails are configured and if the customer doesn't respond in time, the Action scheduler will remove the order. The *Action scheduler* will run every minute and is triggered by the WordPress `WP-Cron `_ system. So you need to make sure WP-Cron is enabled in your WordPress installation, but this is always the case if you have a standard installation. You can inspect the job queue in the WordPress :guilabel:`Tools` menu under :guilabel:`Scheduled actions`. There is no need to cleanup ``Completed`` jobs manually as the system removes them automatically after 30 days. This value can be changed in the `Action scheduler settings <../getting-started/settings.html#action-scheduler>`_. Requirements for consumers ~~~~~~~~~~~~~~~~~~~~~~~~~~ #. Only ``https`` is supported. #. *Fast Event* always uses the ``POST`` method. #. The body payload is always a JSON encoded string. #. Consumers must be able to process multiple requests simultaneously. #. Consumers must respond to a :guilabel:`Test webhook` (See popupmenu) with a HTTP 200. This request has an empty body! #. Consumers must return a HTTP 200 as soon as possible, and not first do all kind of internal operations (database, ...). Make sure the response time is a fraction of a second and not close to a second or even higher. Test it with :guilabel:`Test webhook` in the popupmenu. The ``Duration`` is part of the output. #. Consumers must also respond with a HTTP 200 if the signature is invalid and not respond with something like *Invalid signature*. This prevents information from being revealed to pranksters if they happen to know your URL. HTTP request ~~~~~~~~~~~~ Every HTTP POST has a number of unique HTTP headers: **User-Agent** It will show the version-number of the *Fast Events* plugin and WordPress. Example: ``Fast-Events/1.6.0 (WordPress/6.1.1)`` **X-FE-Webhook-ID** The id of the webhook. You can find the id in the `Webhooks overview`_. **X-FE-Webhook-Source** The location where your WordPress installation lives. Example ``https://vinyl-openair.com/``. **X-FE-Webhook-Topic** The topic that triggered the webhook. See `Webhooks overview`_. **X-FE-Webhook-Resource** The resource can be: ``event``, ``order``, ``scan`` order ``download`` **X-FE-Webhook-Event** See `Webhooks overview`_ and look for the second part in the ``Topic``. **X-FE-Webhook-Delivery-ID** A unique id for every request. Used for debugging purposes to lookup the right request. **X-FE-Webhook-Signature** A unique signature based on the Webhook secret and the body content. Before you start processing the request always first check if the signature does match. Here are some examples how you can very the signature. Use the raw input from the body and do *not* include any possible newlines at the end. .. tabs:: .. code-tab:: javascript // NodeJS example const crypto = require('crypto'); const secret = 'yoursharedsecret'; const payload = 'The JSON payload'; let signature = crypto.createHmac("sha256", secret).update(payload).digest().toString('base64'); .. code-tab:: php ` * :doc:`Orders ` * :doc:`Scans ` * :doc:`Downloads ` .. toctree:: :maxdepth: 1 :hidden: webhooks-events webhooks-orders webhooks-scans webhooks-downloads