Simple Django app for managing Zapier triggers.
Project description
Django Zapier Triggers
Django app for managing Zapier trigger authentication
This app provides the minimal scaffolding required to support a Zapier trigger in your application. Specifically it supports token-based authentication for polling triggers.
Version support
This app supports Django 3.2+ (HttpResponse.headers
), and Python 3.8+
(:=
operator).
How does it work?
The app has a single model that stores an API token (UUID) against a User. The token object has the concept of "scope" which is an array of strings representing API triggers that are supported. In effect it uses the token UUID for authentication, and the token scopes for authorization.
A trigger itself is just a view that returns some data in the prescribed
Zapier format - which in Python terms is a JSON-serializable list of dicts,
each of which must contain an id
attr:
[
{"id": 1, "name": "Fred"},
{ ... }
]
For simple scenarios where you want to return a queryset, there is a base
CBV PollingTriggerView
which you can subclass.
Installation
Install the package using pip / poetry
pip install django-zapier-triggers
Configuration
- Add the app to your
INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
...,
zapier,
]
- Run migrations to add model tables
$ python manage.py migrate
- Add a url for the Zapier auth check
# urls.py
urlpatterns = [
...
path(
"zapier/auth-check/",
zapier.views.zapier_token_check,
name="zapier_auth_check",
),
]
- Configure Zapier trigger (https://platform.zapier.com/docs/triggers)
This app supports the "API Key" auth model for Zapier apps https://platform.zapier.com/docs/apikey
You must configure your Zapier authentication to use API Key authentication, and in the step "Configure a Test Request & Connection Label" you should ensure that you are passing the API Key as a request header called "X-Api-Token", and not in the URL.
NB You will need to host your application somewhere that is visible on
the internet in order to confirm that the authentication works. ngrok
is a good option to run the application locally.
Usage
Now that you have authentication set up, you can create your triggers. A
polling trigger is nothing more that a GET endpoint that supports the
token authentication and that returns an ordered list of JSON objects.
Zapier itself handles deduplication of objects using the id
property
of each object that is returned - you can read more about deduplication
here - https://zapier.com/help/create/basics/data-deduplication-in-zaps
This package is responsible for the endpoint authentication - everything
else is up to you. You can use the polling_trigger
view function
decorator to guard the functions that you set up as triggers. The
decorator takes a required string argument, which is a scope that must
match the incoming request.auth
. The decorator handles request
authentication, setting the request.user
and request.auth
properties.
# views.py
@zapier.decorators.polling_trigger("new_books")
def new_books_trigger(request: HttpRequest) -> JsonResponse:
latest_id = request.auth.get_latest_id("new_books") or -1
books = Book.objects.filter(id__gt=latest_id).order_by("-id")[:25]
data = [{"id": book.id, "title": book.title} for book in books]
return JsonReponse(data)
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-triggers-0.2.3.tar.gz
.
File metadata
- Download URL: django-zapier-triggers-0.2.3.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.4 Darwin/21.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b41376a66a546ef74efbbd406b03ada9101c230cd989dd2416e4a135d62cf21 |
|
MD5 | 111a0eb44f728cf70e476f6116732840 |
|
BLAKE2b-256 | 6072fbd3996ff1f9c3af005ae19f41c5f21a9df34f81160fe40eacf8590d0d39 |
File details
Details for the file django_zapier_triggers-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: django_zapier_triggers-0.2.3-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.4 Darwin/21.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8295c1216e44ad3047b8fd7f6bcdad71dee0049dd1cc8f6179539a36e3fe963f |
|
MD5 | 2fc9b6d6e24f2922497ea38df74a4a55 |
|
BLAKE2b-256 | 345ed4056365559bb85a86e6d2c446519c72da9d4c9f30676e275d633b2895e9 |