Apps

Webhooks


Webhooks App

The webhooks app enables your app to push real-time notifications to other platforms. The Vanty Starter Kit uses HTTPS to send these notifications as a JSON payload. You can then use these notifications to execute actions in your integrated systems.

Use Cases

You can use webhook event notifications to your other platforms when an event occurs, for example:

  • That a subscription payment succeeds (customer.subscription.created)
  • A new subscriber to your newsletter (newsletter.new_subscriber)
  • Critical events such as errors in the payment flow (payments.checkout_failed)

Add a new event

  • Defined your custom events that you may want to listen to.

    apps/webhooks/events.py

    class WebhookEvent(models.TextChoices):
        """
        Webhook events
        Define your custom events here
        """
    
        user_signed_up = "user.signed_up" 
        payment_confirmed = "payments.payment_confirmed" 
        new_subscriber = "newsletter.new_subscriber"  # a new event
    

    Notes

    • We added a new event for the newsletter app. The value that will be saved to the database is newsletter.new_subscriber .
    • Notice that we are using dotted names app_name.event . This is good practice to avoid potential conflicts later as you add more events.
  • Add a webhook signal to listen for the webhook event

    apps/newsletter/views.py

    from apps.webhooks.events import WebhookEvent
    from apps.webhooks.signals import webhook_signal
    
     def new_subscriber_view(request):
         .... # other logic
    
         webhook_signal.send(
             request.user.__class__,
             event=WebhookEvent.new_subscriber,
             data={"email": email},
         )
    

    Notes

    • In the example above, when there is a new subscriber, a new event is sent to the webhooks app.
    • The user’s email will be sent. You can modify this send whatever data you need.
    • That is all the code required for now, when your app is live you can set up the events directly from the dashboard.

Add webhook targets

A webhook target is an endpoint that you will send webhook events to. Webhook targets can be added directly from the dashboard. To create a new webhook, add the name, and URL of the target endpoint, select the events you want to listen to and set the status to enabled.

Webhook Logs for monitoring

Basic information about failed/successful webhook events is available on the detail page for each webhook.

Previous
← Teams