Django (DRF) backed app for managing Zapier triggers.
Project description
Django Zapier Triggers
Django (DRF) app for managing Zapier triggers.
Version support
This app supports Django 3.2+ and Python 3.10+.
Background
This app provides the minimal scaffolding required to support Zapier triggers in your Django application. It is based on DRF.
In addition to the zapier.triggers
Django app, this project includes two additional applications: a complete Zapier CLI application that you can publish to Zapier, and a Demo project that provides the Django support for it. With these two projects you have a complete end-to-end Zapier integration.
Zapier Triggers
A Zapier trigger is an event source for Zapier workflows ("Zaps"), that can operate in one of two modes - "Instant", or "Polling". Either way the net result is that JSON data objects are received by Zapier and can be used as the first step in a Zap.
There is a lot of documentation online from Zapier about how to create a trigger, and I would strongly recommend reading it before attempting to build your own. Here are a couple of good articles to start with:
Prequisites
If you want to run the end-to-end demo you will need:
- A Zapier account
- The Zapier CLI
- ngrok, or some equivalent tunnelling software
What's in the box?
The core implementation detail of this package is the TriggerView
. This is a DRF APIView
class that handles GET
, POST
, and DELETE
methods, mapping them to the Zapier trigger methods for polling ("list"), susbscribe and unsubscribe functions.
GET /triggers/{{trigger}}/
When Zapier makes a GET
request to your application endpoint one of two things is happening. For a REST Hook ("Instant") trigger this is request sample data that Zapier can use to create its Zap builder UI. If your trigger is a push ("Instant") then you can just return static data - as long as it conforms to the same schema as real data. The demo.views.new_book
view demonstrates this.
If your trigger is a polling trigger then this endpoint should return real data - the demo.views.new_film
view is an example of this.
The view returns a 200
status code.
POST /triggers/{{trigger}}/subscriptions/
When Zapier makes a POST
request it is expecting to create a new webhook (rebranded "REST Hook" by Zapier) susbscription. This is handled automatically by the view, which creates a new TriggerSubscription
object for the user + trigger combination, and returns the uuid
property to Zapier, which stores it in its bundle.subscriptionData.id
property.
The view returns a 201
status code.
DELETE /triggers/{{trigger}}/subscriptions/{{subscription_id}}
When Zapier makes a DELETE
request it is expecting to delete the subscription identified by the subscription_id
value, which maps to the uuid
property. We do not delete the subscription but instead mark it as "inactive". This is because we record all of the event data that is sent by a trigger subscription, and we we want to keep this for a period for auditing purposes. If a new POST
request is made for the same user + trigger combination the subscription is reactivated.
The view returns a 204
status code.
Settings
The settings are all read in from the Django setting ZAPIER_TRIGGER
, which is a dict containing the following keys:
STRICT_MODE
The JSON key used to extract the Zapier subscription URL endpoint in the body of the POST
request - defaults to hookUrl
.
TRIGGERS
This is a dict containing the name of the trigger and a string path to a view-like function that must accept a single Request
arg and return a list of JSON-serializable dict objects. Every trigger that your Zapier app supports must be in this setting - otherwise any request made to /triggers/{{trigger}}
will return a 404
.
Demo + zapier-app
The easiest way to work out how this all fits together is to run the demo app and push the zapier-app to Zapier under your own account.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-zapier-trigger-1.0b3.tar.gz
.
File metadata
- Download URL: django-zapier-trigger-1.0b3.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 284dade8d09a71d174f89d19171dcd232928e00e62c66da61669411d6fa06aef |
|
MD5 | 0da7307de6f3ca74484e299a5d93ef3b |
|
BLAKE2b-256 | 92b92cc7c70c79cccddeff7179e810f7677066ebb9bded2a501483f96cd83d15 |
File details
Details for the file django_zapier_trigger-1.0b3-py3-none-any.whl
.
File metadata
- Download URL: django_zapier_trigger-1.0b3-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c33b634d37c033443fea8bbccdb6416c303afc347b354c0373031ef5462c17 |
|
MD5 | 88b22ef6b007d74616b8c5a8fbaad050 |
|
BLAKE2b-256 | 07b6fceaed44b9a23efcb29476b911ad375de83c8925483f08316f80b4dacee8 |