4.3. Webhooks

class backendapp.webhooks.models.Webhook(tag_id, address, fields=None, wh_secretkey=None)[source]

Webhooks are a means of integrating cuplbackend with a 3rd-party web application.

These are user-defined HTTP callbacks.

When a Tag is read via NFC and a new Capture is created, cuplbackend makes an HTTP POST request to a user-specified URL. The body includes Capture data (e.g. a list of timestamped samples) encoded as JSON.

The use of webhooks obviates the need for a 3rd-party application to poll for new Capture data.

An end-user or administrator can add one webhook to each tag.

Webhooks have a simple authentication mechanism; a secret key shared between the cuplbackend and the 3rd-party application. Without this, it would be possible to post fake captures to the 3rd-party application with knowledge of the webhook URL only.

__init__(tag_id, address, fields=None, wh_secretkey=None)

Assign a webhook to a tag. A random secret key is generated if none is supplied.

Parameters
  • tag_id – ID of the Tag.

  • address – An HTTP POST request is made to this URL when the Tag is read via NFC.

  • fields – A list of fields in the Capture model. These will be included with the POST request payload.

  • wh_secretkey – A string of up to 256 characters, to authenticate this application with the POST recipient.

static gen_secret_key()[source]

Generate a random secret key with URL-safe characters.

tagserial

Return a serial string for the Tag that this webhook belongs to.