Dispra Docs

Guides › Guides

Webhooks

8 min · 4 steps · Languages: node, python, go

Webhooks tell your systems when something happens in the project (a deployment went live or failed, a service crashed, a backup finished) without polling.

1. Add an endpoint

Create a webhook with an id you choose and an HTTPS URL. Pick its events, or leave events empty to receive every event. Deliveries to private or local addresses are refused.

cURL

curl -X PUT https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/webhooks/whk_ci_notify \
  -H "Authorization: Bearer dsp_live_YOUR_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://hooks.acme.com/dispra","events":["deploy.succeeded","deploy.failed"]}'

2. Receive deliveries

Each delivery is a POST with a JSON body:

{"id":"evt_01jdk5m7n9q1w3e5r7t9y1u3io","type":"deploy.succeeded","created_at":"2026-12-05T10:16:40Z","project":{"prj":"prj_01jdk3m9x2v7c4q8w5n6b1t0ra","name":"storefront"},"data":{"svc":"svc_01jdk3n2f4g6h8j0k2l4z6x8ca","dep":"dep_01jdk4p7q9w1e3r5t7y9u1i3ob","state":"live"}}

Answer any 2xx within a few seconds, then do the work. The same event can arrive more than once (a retry after your answer was lost): use id to ignore duplicates. Events can arrive out of order: compare created_at when order matters.

3. Verify the signature

Every delivery is signed with the project's webhook secret (reveal or rotate it with the signing secret routes):

X-Dispra-Signature: t=1764924999,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd

v1 is the lowercase hex HMAC-SHA256, keyed with the secret, of t + "." + body, where body is the raw request body exactly as received.

  1. Read the raw body before parsing JSON: re-serialised JSON won't match.
  2. Compute the HMAC and compare it with v1 in constant time.
  3. Refuse a t more than 5 minutes from your clock, so a captured delivery can't be replayed.

Node

import crypto from "node:crypto";
import express from "express";

const SECRET = process.env.DISPRA_WEBHOOK_SECRET;

function verify(header, rawBody) {
  const parts = Object.fromEntries((header || "").split(",").map((p) => p.trim().split("=", 2)));
  const t = Number(parts.t);
  if (!parts.v1 || !Number.isInteger(t)) return false;
  if (Math.abs(Date.now() / 1000 - t) > 300) return false; // 5 minutes
  const expected = crypto.createHmac("sha256", SECRET).update(`${parts.t}.`).update(rawBody).digest();
  const given = Buffer.from(parts.v1, "hex");
  return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}

const app = express();
app.post("/dispra-webhook", express.raw({ type: "application/json" }), (req, res) => {
  if (!verify(req.get("X-Dispra-Signature"), req.body)) return res.status(400).send("bad signature");
  const event = JSON.parse(req.body.toString("utf8"));
  res.sendStatus(204); // answer first, then work
  handle(event);
});
app.listen(3000);

Python

import hashlib, hmac, os, time
from flask import Flask, request, abort

SECRET = os.environ["DISPRA_WEBHOOK_SECRET"].encode()
app = Flask(__name__)

def verify(header, body):
    parts = dict(p.strip().split("=", 1) for p in (header or "").split(",") if "=" in p)
    t, v1 = parts.get("t"), parts.get("v1")
    if not t or not v1 or abs(time.time() - int(t)) > 300:
        return False
    expected = hmac.new(SECRET, t.encode() + b"." + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, v1)

@app.post("/dispra-webhook")
def webhook():
    if not verify(request.headers.get("X-Dispra-Signature"), request.get_data()):
        abort(400)
    event = request.get_json()
    # dedupe on event["id"], then act
    return "", 204

Go

func verify(secret, header string, body []byte) bool {
	var ts, sig string
	for _, part := range strings.Split(header, ",") {
		k, v, _ := strings.Cut(strings.TrimSpace(part), "=")
		switch k {
		case "t":
			ts = v
		case "v1":
			sig = v
		}
	}
	t, err := strconv.ParseInt(ts, 10, 64)
	if err != nil || sig == "" || math.Abs(time.Since(time.Unix(t, 0)).Seconds()) > 300 {
		return false
	}
	given, err := hex.DecodeString(sig)
	if err != nil {
		return false
	}
	mac := hmac.New(sha256.New, []byte(secret))
	mac.Write([]byte(ts + "."))
	mac.Write(body)
	return hmac.Equal(given, mac.Sum(nil))
}

4. Retries

Anything but a 2xx in time counts as a failure and is retried 5 times over about an hour (1, 5, 10, 20 and 24 minutes later), then the delivery is marked failed. List deliveries with state=failed shows them. After rotating the secret, update your receiver right away: deliveries are signed with the new secret from then on.