How to Subscribe to a Webhook

To enable notifications, you have to subscribe to event(s) first.
This is done by calling the "subscriptions" endpoint:


API URL:

POST: https://yourproject.vouchery.app/api/v2.1/subscriptions


API REQUEST BODY:

In the request body, please provide:

  • a list of event(s) you wish to subscribe to.
  • a "callback_url" - which should be an HTTPS endpoint in your system where the event(s) will be delivered.
  • Optionally: headers - in case your system requires that.
  • Optionally: all_events - in case you want to subscribe to all possible Vouchery events.
  • Optionally: custom_events - in case you want to use your own custom events.

๐Ÿ“˜

Let's examine the following scenario:

"I want to be notified whenever a new customer is created, and my system requires custom headers"


  • In this case, we rely on one of the predefined vouchery event called 'customer_created,' which must be passed in our API call.


    ๐Ÿšง

    Full list of supported events can be found here: https://docs.vouchery.io/v2.1/docs/supported-events



  • Additionally we set "all_events" and "custom_events" to false as we want to be notified only on that specific event.

  • Finally, in the "headers" section, we have to pass our data that is required by our system to successfully receive a notification from Vouchery system.

{
"callback_url": "https://<your_server_url>",
 "events": [
           "customer_created"
 ],       
"all_events": false,
 "custom_events": false,
 "headers": {"Authorization":"Bearer_example_token"}
}

where:

PropertyDescription
callback_urlIs the url that will be invoked when an event occurs
eventsPredefined Vouchery event(s) https://docs.vouchery.io/v2.1/docs/supported-events or a custom event(s).
all_eventsif set to true, you will be subscribed to all predefined events that are shipped by Vouchery, if you do not pass anything in the โ€œeventsโ€.
custom_eventsIf set to true, you will subscribe to all custom events passed in the โ€œeventsโ€.
headersData required for authorization

In the response, you will receive a subscription "id" along with some additional parameters such as "created_at" and "updated_at".

๐Ÿšง

The "id" - of the subscription is returned in the response and can be used to delete the subscription.