Webhooks

Push notifications for PatientFlow completion, refresh failures, and background-pull events. Build a verified receiver in minutes.

Webhooks let Medblocks notify your backend the instant something happens in Connect. A PatientFlow finishes, a refresh token stops working, a background pull settles. Your server registers an HTTPS endpoint and Medblocks delivers signed JSON payloads to it.

This section covers everything you need to consume webhooks. Building a receiver, verifying signatures, managing endpoints from your backend, retries, and replaying events. For the underlying model read Concept · Webhooks.

Event Catalog

Event typeFires whenUse it for
patient_flow.completedPatient finished the hosted flow (success or failure).Update your “connected” UI, kick off downstream workflows.
connection.token_refresh_failedA previously active connection lost its refresh token.Prompt the patient to reconnect.
records.sync.completedA background pull finished and new records are available.Trigger downstream processing, refresh dashboards.
records.sync.failedA background pull errored.Page the on-call team.

In This Section

Receiver Contract

At a glance, your receiver must:

  1. Accept POST requests over HTTPS with a JSON body.
  2. Read the raw request body (no JSON pre-parsing) before computing the signature.
  3. Verify the Medblocks-Signature header against the raw body and your endpoint’s signing secret.
  4. Return a 2xx response within 5 seconds (otherwise Medblocks retries).
  5. Be idempotent. The same event.id may be delivered more than once.

Everything else is the SDK’s job. Medblocks.webhooks.constructEvent(rawBody, signature, secret) does steps 3 and returns a typed WebhookEvent you can switch over.

Quick Sketch

import { Medblocks, MedblocksSignatureError } from "@medblocks/connect";

async function handle(req: Request): Promise<Response> {
  const rawBody = await req.text();
  const signature = req.headers.get("Medblocks-Signature");

  try {
    const event = await Medblocks.webhooks.constructEvent(
      rawBody,
      signature,
      process.env.MEDBLOCKS_WEBHOOK_SECRET!,
    );

    if (event.type === "patient_flow.completed") {
      const flow = event.data.object;
      // ...your business logic
    }

    return new Response("ok", { status: 200 });
  } catch (err) {
    if (err instanceof MedblocksSignatureError) {
      return new Response("bad signature", { status: 400 });
    }
    throw err;
  }
}

The Quickstart expands this with route wiring, raw-body handling per framework, and event.type discrimination.