Webhooks
A webhook tells your system that something changed, so it does not have to poll. Deliveries are signed, carry identifiers and states only, and are retried when your endpoint does not answer.
Create an endpoint#
In your workspace, open API and add a webhook endpoint. This needs the Owner, Administrator or Developer role.
- The address must be a public
httpshost name. An IP address,localhost, a.localor.internalname, or an address with credentials in it is refused. - Choose at least one event type.
- A workspace can have up to 10 endpoints.
The signing secret, starting with whsec_, is shown once when the endpoint is created. The platform stores it sealed and cannot show it again: to change it, remove the endpoint and add it again.
Events#
| Type | Sent when | Subject | Data |
|---|---|---|---|
requisition.received | A new requisition arrived from a connection. | requisition | source, priority |
requisition.updated | A requisition changed in the source system, or was closed there. | requisition | status, and reason when it was closed at the source |
suggestion.created | A suggestion was prepared for a requisition. | requisition | engine, confidence |
decision.recorded | A radiologist approved, modified, rejected or asked for more information. | requisition | action, submitted |
submission.confirmed | The approved protocol was written to the source system and read back as saved. | requisition | none |
submission.failed | The write failed or could not be confirmed. The requisition needs attention. | requisition | errorKind |
connection.status_changed | A connection was activated, paused, or moved to error after repeated failures. | connection | status |
job.failed | A queued job ended in failure and will not be retried. | job | kind, errorKind |
The same events are available, newest first, from GET /v1/events with the events:read scope. Use it to catch up after downtime.
Payload#
{
"id": "p27z9x7c5v3b1n8m6q4w2e0r9t",
"type": "submission.confirmed",
"created": 1795787404,
"organization": "example",
"subject": { "type": "requisition", "id": "k57c2q9x4m1v8b3n6z0d5f7h2j" },
"data": {}
}| Field | Meaning |
|---|---|
id | The event's id. The same on every retry, so use it to ignore a delivery you have already handled. |
type | One of the types above. Also sent as the Epic-Direct-Event header. |
created | When the event happened, in Unix seconds. |
organization | The workspace's short name, as in its address. |
subject | What the event is about: a type and an id. |
data | A few states or flags. Never patient data. |
Verify the signature#
Every delivery carries a signature header. Check it before you trust the body.
Epic-Direct-Signature: t=1795787404,v1=5f2b…c9e1- Take
tandv1from the header. - Compute HMAC-SHA256 over
t, a full stop, and the raw request body, using the whole signing secret (includingwhsec_) as the key. Encode the result as lower-case hex. - Compare it with
v1using a constant-time comparison. - Reject a delivery whose
tis too old. The platform does not set this window for you; five minutes is a reasonable choice.
import { createHmac, timingSafeEqual } from "node:crypto";
// rawBody must be the exact bytes received, before any JSON parsing.
export function verify(rawBody, signatureHeader, secret, toleranceSeconds = 300) {
const parts = Object.fromEntries(signatureHeader.split(",").map((p) => p.split("=")));
const t = parts.t ?? "";
if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
const given = String(parts.v1 ?? "");
return given.length === expected.length && timingSafeEqual(Buffer.from(given), Buffer.from(expected));
}import hashlib, hmac, time
# raw_body must be the exact bytes received, before any JSON parsing.
def verify(raw_body: bytes, signature_header: str, secret: str, tolerance: int = 300) -> bool:
parts = dict(p.split("=", 1) for p in signature_header.split(",") if "=" in p)
t = parts.get("t", "")
if not t.isdigit() or abs(time.time() - int(t)) > tolerance:
return False
expected = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts.get("v1", ""))Verify against the bytes you received. Parsing the JSON and serialising it again changes the bytes and the check will fail.
Delivery and retries#
| Request | POST, Content-Type: application/json, User-Agent: Epic.direct-Webhooks/1 |
|---|---|
| Success | Any 2xx status. |
| Timeout | 10 seconds. Answer first, then do the work. |
| Redirects | Not followed. A redirect counts as a failure. |
| Attempts | Up to 5 for each delivery. |
| Wait between attempts | 30 seconds, 2 minutes, 8 minutes, 32 minutes. |
- After the fifth failed attempt the delivery is marked failed and is not sent again.
- When 20 attempts in a row have failed across an endpoint’s deliveries, the endpoint is paused and the pause is written to the audit trail. Nothing is sent to a paused endpoint. Resume it on the API page once it is fixed; a successful delivery resets the count.
- Deliveries are not guaranteed to arrive in the order the events happened. Use the API as the source of truth for current state.
- The API page shows the most recent deliveries for each endpoint with their status and response code.