Skip to main content

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

  1. Add the app to your INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
    ...,
    zapier,
]
  1. Run migrations to add model tables
$ python manage.py migrate
  1. Add a url for the Zapier auth check
# urls.py
urlpatterns = [
    ...
    path(
        "zapier/auth-check/",
        zapier.views.zapier_token_check,
        name="zapier_auth_check",
    ),
]
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-zapier-triggers-0.3b1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_zapier_triggers-0.3b1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file django-zapier-triggers-0.3b1.tar.gz.

File metadata

  • Download URL: django-zapier-triggers-0.3b1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.3.0

File hashes

Hashes for django-zapier-triggers-0.3b1.tar.gz
Algorithm Hash digest
SHA256 d8dc7e1de3aba009e4a6f7b4f02597c98b6b6c7c826d6a43920b0ed989886175
MD5 260a8402a62491f349f214e06066d364
BLAKE2b-256 bde9f7b6785e60ae4a9008c6fb8b404fa11992e433cb2d1d75229b283f8bd8e9

See more details on using hashes here.

File details

Details for the file django_zapier_triggers-0.3b1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_zapier_triggers-0.3b1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5bc0014552bdb43e915c9444b07ed88f8e9adfd3cd47688c3cfc7478d1d8537
MD5 99313f2acd153384be3a96d276320e9c
BLAKE2b-256 5f0ca5bab0f2d2db930cb98189ad982a9ce3c978a6b4be255e5f78b0ae0723ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page