> ## Documentation Index
> Fetch the complete documentation index at: https://developers.docistra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Get every change in Docistra the moment it happens.

Docistra changes all day without your system: the AI agent registers patients and books on WhatsApp, patients book on the clinic's page, reception cancels and checks people in. Webhooks send you each change as it happens.

## Set your endpoint

Each API key has one webhook endpoint. Set it in Docistra (**Settings > Integrations > API**, under the key) or through the API:

```bash theme={null}
curl -X POST https://docistra.com/api/v1/webhooks \
  -H "Authorization: Bearer $DOCISTRA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://his.example.com/docistra/webhooks", "events": [] }'
```

The response includes the signing `secret` (`whsec_...`), only this once. An empty `events` list means every event. The URL must be `https://` and reachable from the internet.

## What arrives

```http theme={null}
POST /docistra/webhooks HTTP/1.1
Content-Type: application/json
User-Agent: Docistra-Webhooks/1.0
X-Docistra-Event: appointment.cancelled
X-Docistra-Event-Id: 0b8f6c1e-7f0a-4b8e-9a51-3f2d6c7e8a90
X-Docistra-Signature: t=1764583200,v1=5f2b0c...
```

```json theme={null}
{
  "id": "0b8f6c1e-7f0a-4b8e-9a51-3f2d6c7e8a90",
  "type": "appointment.cancelled",
  "created_at": "2026-12-01T09:12:44.512Z",
  "organization_id": "3ff61703-...",
  "data": {
    "object": {
      "object": "appointment",
      "id": "c2a1...",
      "external_id": "A-55012",
      "status": "cancelled",
      "patient_external_id": "P-10293",
      "doctor_external_id": "D-7",
      "start": "2026-12-03T15:30:00+00:00",
      "cancel_reason": "doctor_day_off"
    },
    "previous": { "previous_status": "reserved" }
  }
}
```

`data.object` is the record as it is when the webhook is sent, in the same shape as the API's `GET`. `data.previous` says what changed.

## Your endpoint should

1. **Check the signature** before trusting the body. See [Verify signatures](https://developers.docistra.com/webhooks/verify-signatures.md).
2. **Answer 2xx within 10 seconds.** Do heavy work after answering (a queue).
3. **Dedupe on `X-Docistra-Event-Id`.** A retry carries the same id, so store the ids you processed.
4. **Not rely on order.** Two changes a second apart can arrive in either order. Compare `updated_at` with what you have.

## Retries

Anything other than a 2xx (or no answer within 10 seconds) is retried after 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours and 12 hours. After that the event is marked failed. Catch up with [`updated_since`](https://developers.docistra.com/concepts/pagination) if your endpoint was down longer.

The clinic sees each delivery (delivered, retrying, failed, with the HTTP status) under the key in Docistra, and can send a test event with **Send test**. A test event has the type `ping`.

## Your own changes don't come back

A change your own API call made is not sent back to the same key's endpoint. If you cancel an appointment through the API, you don't get `appointment.cancelled` for it. Changes made in Docistra, or with another key, are sent.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.