Developer docs

Webhooks: signed event deliveries for every install

Dispense Flow developers

In short

For every store that installs your app, each event your app subscribes to (and the store's grant covers) is POSTed to your webhook URL as JSON { id, type, occurredAt, merchantId, data }, signed in X-DFlow-Signature: t=<unix>,v1=<hex> with HMAC-SHA256 over t + "." + rawBody using your webhook secret. Answer 2xx within 10 seconds; failures retry after 1 minute, 5 minutes, 30 minutes, 2 hours, 12 hours and 24 hours.

The envelope

Every delivery is one JSON body. merchantId is the store, the same id the token exchange returned as store_id. data is the event's own fields, listed per event on Events.

FieldTypeWhat it is
idstringThe event's id. Use it to drop a duplicate delivery.
typestringThe event type, also in the X-DFlow-Event-Type header.
occurredAtstringWhen it happened, ISO date.
merchantIdstringYour store's id.
dataobjectThe event's own fields, listed per event below.

Headers

X-DFlow-Signature is the signature. X-DFlow-Event-Id is the event id: store it and drop a duplicate (a retry after a timeout can deliver an event twice). X-DFlow-Event-Type repeats the type. X-DFlow-Delivery-Id identifies the attempt.

How do I verify the signature?

Recompute the HMAC over the raw body, before parsing it, and compare in constant time. Reject a timestamp more than five minutes from your clock, which stops a captured request being replayed later.

// Node.js (Express): keep the raw body for this route.
import crypto from "node:crypto";
import express from "express";

const app = express();
app.post("/dflow/webhooks", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("x-dflow-signature") ?? "";
  const parts = Object.fromEntries(header.split(",").map((kv) => kv.split("=")));
  const t = Number(parts.t);
  if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > 300) return res.sendStatus(400);
  const expected = crypto.createHmac("sha256", process.env.DFLOW_WEBHOOK_SECRET)
    .update(`${t}.${req.body}`).digest("hex");
  const ok = parts.v1 && expected.length === parts.v1.length &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
  if (!ok) return res.sendStatus(400);
  const event = JSON.parse(req.body.toString("utf8"));
  // Queue the work, answer at once.
  res.sendStatus(204);
});
# Python
import hmac, hashlib, time

def verify(secret: str, body: bytes, header: str, tolerance: int = 300) -> bool:
    parts = dict(kv.split("=", 1) for kv in header.split(","))
    t = int(parts.get("t", "0"))
    if abs(time.time() - t) > tolerance:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))

Retries, ordering and failing endpoints

A delivery that does not answer 2xx within 10 seconds is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 12 hours and 24 hours, then marked dead. Redirects are not followed.

Each install's endpoint receives one delivery at a time, oldest first, so events arrive in order; a failure holds the ones behind it until it succeeds or dies.

An endpoint that delivers nothing for three days is set to failing and stops receiving new events. Read GET /v1/app-api/webhooks to see its state and its last fifty deliveries.

What do payloads never contain?

Intake answers, prescriptions, diagnoses or medication names for prescription products. Events carry ids, amounts and statuses; an app with the right scope fetches more through the App API. Visit events (flow_session.*) go only to apps granted the PHI scope read_visits.

Test events

From a test store in the developer dashboard, send any event with sample data. It is delivered exactly like a real one, with isTest: true in data. Orders placed with test cards on a live store also carry isTest: true.

Questions

Which URL can I use?

An https URL on a public host. Private, loopback and link-local addresses are refused. For local development, use a tunnel.

How do I know which store an event is from?

The envelope's merchantId, the same id the OAuth token exchange returned as store_id.