Webhooks and events
Get told when a referral changes, instead of polling for it.
Scan.com can tell your system when something happens to one of your referrals: its status changes, a report is ready, or scan images are ready. You can hear about it in two ways, and you can use either or both:
- Webhooks: we send a signed
POSTrequest to an HTTPS URL you choose, a few seconds after the change. - The events feed: you read
GET /api/v1/eventswith a cursor, and get every event in order.
Both carry the same events, with the same ids. Events say that something changed, not every detail of it: you fetch the referral with the endpoints you already use. Polling GET /api/v1/referrals sorted by updated_at keeps working as before.
Authentication
The webhook endpoint calls (/api/v1/webhook_endpoints and everything under it) and the events feed (/api/v1/events) use your API client credentials with HTTP Basic authentication, as POST /api/v1/token and POST /api/v1/users already do: your client_id is the username and your client_secret is the password. These calls act for your whole organisation, not for one user, so you don't need a user token for them. Every other call in this guide, such as fetching a referral or the sandbox endpoints, uses a user's bearer token as usual.
curl https://api-sandbox.uk.scan.com/api/v1/webhook_endpoints \
-u "$SCAN_CLIENT_ID:$SCAN_CLIENT_SECRET"The sandbox (api-sandbox.uk.scan.com) and production (api.uk.scan.com) are separate. Each has its own credentials, endpoints, secrets and events.
Managing webhook endpoints
A webhook endpoint is a URL of yours that receives events. You can have up to 5 endpoints in each environment, for example your live receiver and a second system, or an old and a new URL while you move.
Create an endpoint
curl https://api-sandbox.uk.scan.com/api/v1/webhook_endpoints \
-u "$SCAN_CLIENT_ID:$SCAN_CLIENT_SECRET" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/scan/webhooks",
"event_types": ["referral.status_changed", "referral.report_ready"],
"notification_email": "[email protected]",
"description": "Main receiver"
}'| Field | Required | Notes |
|---|---|---|
url | Yes | HTTPS only, on port 443 or 8443. It must resolve to a public address: IP addresses, localhost and private or internal addresses are rejected. To receive events on your own machine while testing, use an HTTPS tunnel such as ngrok. |
notification_email | Yes | Where we write if this endpoint keeps failing (see failing endpoints). Use a shared team address. |
event_types | No | The event types this endpoint receives. Defaults to ["*"], every type. Unknown types are rejected. |
description | No | Your own label. |
secret | No | Your own signing secret, if you want to choose it (see the signing secret). |
The response is the endpoint, including its secret. This is the only time we show it, so store it now, for example in your secrets manager. If you lose it, rotate it.
{
"id": "we_5d1e2c3b-8a4f-4b6e-9c1d-2f3a4b5c6d7e",
"url": "https://example.com/scan/webhooks",
"description": "Main receiver",
"event_types": ["referral.status_changed", "referral.report_ready"],
"notification_email": "[email protected]",
"enabled": true,
"disabled_reason": null,
"disabled_at": null,
"failing_since": null,
"secret": "whsec_cN+YkCxff7ibwJrYZNdnf9H6GH0OvyQ9ZHvb+s9F5Pw=",
"created_at": "2026-11-25T12:00:00Z",
"updated_at": "2026-11-25T12:00:00Z"
}A sixth endpoint, a URL that fails the checks above, or an unknown event type returns 422 with a message saying what to fix.
The signing secret
Each endpoint has its own signing secret, separate from your API client_secret. Rotating one never affects the other.
By default we generate a strong secret for you. If you'd rather choose it, send secret in the Standard Webhooks format: whsec_ followed by base64 of 24 to 64 random bytes. Anything else returns 422. For example:
echo "whsec_$(openssl rand -base64 32)"List, show, update and delete
| Call | What it does |
|---|---|
GET /api/v1/webhook_endpoints | Lists your endpoints. Secrets are never included. |
GET /api/v1/webhook_endpoints/:id | Shows one endpoint, with its delivery counts for the last 24 hours and the last error (HTTP status or connection error, and when) of its latest failed attempt. |
PATCH /api/v1/webhook_endpoints/:id | Changes url, event_types, notification_email, description or enabled. |
DELETE /api/v1/webhook_endpoints/:id | Deletes the endpoint. Its pending deliveries stop and its delivery log is deleted with it. Events stay in the events feed. |
To pause an endpoint, send {"enabled": false}. To turn it back on, send {"enabled": true}. While it is disabled, events are still recorded and appear in the feed, but the endpoint gets no deliveries; after re-enabling it, recover what it missed.
Each endpoint shows why it is disabled, if it is:
disabled_reason | Meaning |
|---|---|
partner | You disabled it. |
failing | We disabled it after 5 days of failed deliveries. |
gone | Your receiver answered 410 Gone, which we take as "stop sending". |
Events
The event object
Every event has the same envelope. The webhook request body and each item of the events feed are the same JSON.
{
"id": "msg_2f6c1c1e-6f3a-4c8e-9b1a-0d4b8b7e5a11",
"type": "referral.status_changed",
"timestamp": "2026-11-25T12:34:56Z",
"environment": "production",
"data": {}
}| Field | Notes |
|---|---|
id | The event id. It is also sent as the webhook-id header, and it never changes: use it to ignore duplicates. |
type | One of the event types below. |
timestamp | When the event was recorded, in UTC. |
environment | production or sandbox, so one receiver can tell them apart. |
data | The facts that changed. Its fields depend on type. |
Every referral event's data includes:
| Field | Notes |
|---|---|
referral_id | The id to use with GET /api/v1/referrals/:id. |
reference | The referral reference, for example R123456. |
internal_reference | Your own reference for the referral, as you sent it, or null. |
user_id | The user the referral belongs to. Fetch the referral with that user's token. |
No patient data
Events never contain patient data: no names, email addresses, phone numbers, dates of birth, addresses, clinical details, report contents or document links. To get the details, fetch the referral, its reports or its images with the endpoints you already use.
Never put personal data in
internal_reference. It is the only free text we include in events, and it is repeated in every event for that referral. Use your own record id, not a patient name or email address.
Event types
| Type | Sent when |
|---|---|
referral.status_changed | A referral's status changes: Submitted, Received, Confirmed, Scan Booked, On hold, Completed or Cancelled. It is also sent if a referral moves back, for example from Completed to Scan Booked. |
referral.report_ready | A report becomes available for a referral. It is sent once per report, so a second report or an addendum sends another event. |
referral.images_ready | A scan image becomes available for a referral. It is sent once per image. |
webhook.test | You ask for a test event (see testing). It only goes to the endpoint you asked for, and it isn't in the events feed. |
There is one referral.status_changed type for every status, rather than a type per status. If, say, only completions matter to you, subscribe to referral.status_changed and check data.status_code.
We may add new event types and new fields in data. Ignore types and fields you don't know, rather than failing on them. An endpoint subscribed to ["*"] receives new types as soon as they exist; an endpoint with a list of types only receives the types on its list.
referral.status_changed
referral.status_changed{
"id": "msg_2f6c1c1e-6f3a-4c8e-9b1a-0d4b8b7e5a11",
"type": "referral.status_changed",
"timestamp": "2026-11-25T12:34:56Z",
"environment": "production",
"data": {
"referral_id": "7b2d3f1e-1c2a-4f7e-8d7a-3e5b9c0a1f22",
"reference": "R123456",
"internal_reference": "ACME-99812",
"user_id": "0f3c9a4e-5b6d-4e1f-9a2b-7c8d9e0f1a2b",
"status": "Completed",
"status_code": "completed",
"previous_status": "Scan Booked",
"previous_status_code": "scan_booked",
"report_status": "Ready",
"status_changed_at": "2026-11-25T12:34:50Z"
}
}status is the label you already see in GET /api/v1/referrals. status_code is a fixed value for your code to compare:
status | status_code |
|---|---|
| Submitted | submitted |
| Received | received |
| Confirmed | confirmed |
| Scan Booked | scan_booked |
| On hold | on_hold |
| Completed | completed |
| Cancelled | cancelled |
previous_statusandprevious_status_codeare the status before this change. On a referral's first event (normally Submitted) they areIn Draft/in_draftorCreated/created, the status a referral has before it is submitted; we don't send events for those two. They arenullif the referral was created already at a later status.status_changed_atis when the referral reached this status. If a referral moves back to an earlier status (for example from Completed to Scan Booked), it is the time of the move back, when we recorded the change.report_statusisPending,Readyornull(before the referral is sent to the imaging provider), as inGET /api/v1/referrals.- Don't fetch the report on the move to Completed, even when
report_statusisReady: wait forreferral.report_ready.
referral.report_ready
referral.report_ready{
"id": "msg_9a0e7b4c-2d1f-4e3a-8b5c-6d7e8f9a0b1c",
"type": "referral.report_ready",
"timestamp": "2026-11-25T12:34:56Z",
"environment": "production",
"data": {
"referral_id": "7b2d3f1e-1c2a-4f7e-8d7a-3e5b9c0a1f22",
"reference": "R123456",
"internal_reference": "ACME-99812",
"user_id": "0f3c9a4e-5b6d-4e1f-9a2b-7c8d9e0f1a2b",
"scan_report_id": "c41b6a2d-3e4f-4a5b-9c6d-7e8f9a0b1c2d",
"report_added_at": "2026-11-25T12:34:40Z"
}
}Fetch the report with GET /api/v1/referrals/:referral_id/scan_reports/:scan_report_id.
Fetch the report when this event arrives, not on the move to Completed. Completed can arrive a few seconds before the report is ready, because we parse and watermark the report first.
referral.images_ready
referral.images_ready{
"id": "msg_51d2c3b4-a5f6-4e7d-8c9b-0a1b2c3d4e5f",
"type": "referral.images_ready",
"timestamp": "2026-11-25T12:34:56Z",
"environment": "sandbox",
"data": {
"referral_id": "7b2d3f1e-1c2a-4f7e-8d7a-3e5b9c0a1f22",
"reference": "R123456",
"internal_reference": null,
"user_id": "0f3c9a4e-5b6d-4e1f-9a2b-7c8d9e0f1a2b",
"scan_image_id": "e8f0a1b2-c3d4-4e5f-8a9b-0c1d2e3f4a5b",
"approved_scan_images_count": 2,
"approved_at": "2026-11-25T12:34:41Z"
}
}Fetch the image with GET /api/v1/referrals/:referral_id/scan_images/:scan_image_id. approved_scan_images_count is the number of images now available for the referral.
webhook.test
webhook.test{
"id": "msg_0c77d8e9-f0a1-4b2c-9d3e-4f5a6b7c8d9e",
"type": "webhook.test",
"timestamp": "2026-11-25T12:34:56Z",
"environment": "production",
"data": {
"webhook_endpoint_id": "we_5d1e2c3b-8a4f-4b6e-9c1d-2f3a4b5c6d7e",
"message": "Test event from scan.com"
}
}When events stop for a referral
We record events for a referral until 30 days after it is Completed or Cancelled. After that, nothing is recorded or sent for it, even if it changes, and even if it is later reopened. This covers late reports and the scan images that usually arrive in the days after a scan.
For changes after that (for example an extra scan image months later), poll GET /api/v1/referrals sorted by updated_at, or fetch the referral.
Verifying signatures
Every webhook request is signed, so you can check it came from Scan.com and wasn't changed or replayed. Signing follows the Standard Webhooks specification, which has ready-made libraries for most languages. Verify every request before you act on it, and answer 401 to one that fails.
The request
POST /scan/webhooks HTTP/1.1
Host: example.com
Content-Type: application/json
User-Agent: Scan-Webhooks/1.0
webhook-id: msg_2f6c1c1e-6f3a-4c8e-9b1a-0d4b8b7e5a11
webhook-timestamp: 1795610096
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
{"id":"msg_2f6c1c1e-6f3a-4c8e-9b1a-0d4b8b7e5a11","type":"referral.status_changed",...}| Header | Notes |
|---|---|
webhook-id | The event id, the same as id in the body. |
webhook-timestamp | When this attempt was signed, in Unix seconds. It changes on every attempt. |
webhook-signature | One or more signatures separated by spaces, each v1, followed by base64. There are two while you rotate the secret; accept the request if any one of them matches. |
What is signed
- Join the id, the timestamp and the raw request body with dots:
{webhook-id}.{webhook-timestamp}.{body}. Use the body exactly as received: parsing the JSON and serialising it again changes the bytes and breaks the signature. - Take your secret, remove the
whsec_prefix, and base64-decode the rest. That gives the key. - Compute HMAC-SHA256 of the joined string with that key, and base64-encode it.
- Compare it with each
v1,signature in the header, using a constant-time comparison. - Reject the request if
webhook-timestampis more than 5 minutes away from your clock. This stops someone replaying an old request.
The Standard Webhooks libraries do all of this for you, including the timestamp check and several signatures.
Ruby
With the standardwebhooks gem, in a Rails controller (leave out skip_forgery_protection if your controller inherits from ActionController::API):
require 'standardwebhooks'
class ScanWebhooksController < ApplicationController
skip_forgery_protection
def create
webhook = StandardWebhooks::Webhook.new(ENV.fetch('SCAN_WEBHOOK_SECRET'))
headers = %w[webhook-id webhook-timestamp webhook-signature].to_h { |name| [name, request.headers[name]] }
event = webhook.verify(request.raw_post, headers)
ScanEventJob.perform_later(event) # do the work in the background
head :no_content
rescue StandardWebhooks::WebhookVerificationError
head :unauthorized
end
endWithout a library:
require 'base64'
require 'openssl'
TOLERANCE_IN_SECONDS = 5 * 60
def valid_scan_signature?(secret:, id:, timestamp:, signature_header:, body:)
return false if (Time.now.to_i - timestamp.to_i).abs > TOLERANCE_IN_SECONDS
key = Base64.decode64(secret.delete_prefix('whsec_'))
expected = Base64.strict_encode64(OpenSSL::HMAC.digest('SHA256', key, "#{id}.#{timestamp}.#{body}"))
signature_header.split.any? do |versioned|
version, signature = versioned.split(',', 2)
version == 'v1' && OpenSSL.secure_compare(signature.to_s, expected)
end
endNode.js
With the standardwebhooks package and Express. Read the body as raw bytes, not parsed JSON:
import express from "express";
import { Webhook } from "standardwebhooks";
const app = express();
const webhook = new Webhook(process.env.SCAN_WEBHOOK_SECRET);
app.post("/scan/webhooks", express.raw({ type: "application/json" }), (req, res) => {
let event;
try {
event = webhook.verify(req.body.toString("utf8"), req.headers);
} catch (error) {
return res.sendStatus(401);
}
queue.add(event); // do the work in the background
res.sendStatus(204);
});Python
With the standardwebhooks package and Flask:
import os
from flask import Flask, request
from standardwebhooks.webhooks import Webhook, WebhookVerificationError
app = Flask(__name__)
webhook = Webhook(os.environ["SCAN_WEBHOOK_SECRET"])
@app.post("/scan/webhooks")
def scan_webhooks():
try:
event = webhook.verify(request.get_data(), dict(request.headers))
except WebhookVerificationError:
return "", 401
queue.enqueue(handle_scan_event, event) # do the work in the background
return "", 204Libraries for other languages (Go, Java, C#, PHP, Rust and more) are listed in the Standard Webhooks repository.
Responding, retries and failing endpoints
Respond quickly
Answer with any 2xx status within 15 seconds (and accept the connection within 5). We ignore the response body. Save the event and process it in the background, rather than fetching the referral before you answer.
Anything else counts as a failure: another status, a timeout, a connection or TLS error, or a redirect. We don't follow redirects, so give us the final URL.
Retries
After a failed attempt we try again, with a little random spread, after:
| Retry | Wait after the previous attempt |
|---|---|
| 1 | 5 seconds |
| 2 | 5 minutes |
| 3 | 30 minutes |
| 4 | 2 hours |
| 5 | 5 hours |
| 6 | 10 hours |
| 7 | 10 hours |
That is about 27 hours in all. After the last retry the delivery is marked failed; you can still resend it or recover it.
- If you answer
429or503with aRetry-Afterheader (in seconds or as an HTTP date), we never wait less than the table says. We wait longer if you ask, up to the wait of the retry after it: if retry 3 is due, we wait at least 30 minutes and at most 2 hours. Retries 6 and 7 already have the longest wait, so they stay at 10 hours, and after retry 7 fails there are no more retries. - If you answer
410 Gone, we disable the endpoint straight away (disabled_reason: gone) and stop sending to it.
Failing endpoints
If an endpoint keeps failing:
- After 24 hours without a single success, we email its
notification_emailonce to warn you. - After 5 days without a success, we disable it (
enabled: false,disabled_reason: failing) and email the same address again.
GET /api/v1/webhook_endpoints/:id shows failing_since and the last error, to help you find the cause. Once you've fixed your receiver:
- Turn the endpoint back on with
PATCH /api/v1/webhook_endpoints/:idand{"enabled": true}. - Send yourself what you missed with a recovery, or read the events feed from your last cursor.
Idempotency and ordering
You may receive the same event more than once, for example when your receiver handled it but its answer didn't reach us in time. The event id (and the webhook-id header) is the idempotency key: it stays the same on every retry, resend and recovery, and in the events feed. Store the ids you've processed and ignore any you've already seen. If you use both webhooks and the feed, the same id lets you dedupe across them.
Webhooks can arrive out of order. Retries and parallel deliveries mean a Completed event can reach you before the Scan Booked one. Treat an event as a signal to fetch the referral, and use the state the API returns, rather than applying events one after another. Each event also carries the time of the change (status_changed_at, report_added_at, approved_at) if you need to compare. If you need events strictly in order, use the events feed.
The events feed
GET /api/v1/events returns your events oldest first, in the order we recorded them. It covers every referral of every user in your organisation, and it works whether or not you have webhook endpoints, so you can use it on its own instead of webhooks.
curl "https://api-sandbox.uk.scan.com/api/v1/events?limit=100" \
-u "$SCAN_CLIENT_ID:$SCAN_CLIENT_SECRET"{
"data": [
{
"id": "msg_2f6c1c1e-6f3a-4c8e-9b1a-0d4b8b7e5a11",
"type": "referral.status_changed",
"timestamp": "2026-11-25T12:34:56Z",
"environment": "sandbox",
"data": { "referral_id": "7b2d3f1e-1c2a-4f7e-8d7a-3e5b9c0a1f22", "...": "..." }
}
],
"next_cursor": "eyJzIjoxMjM0NX0",
"has_more": true
}| Parameter | Notes |
|---|---|
cursor | The next_cursor from your previous call. Treat it as an opaque string. |
limit | Events per page: 50 by default, 100 at most. |
type | One type, or several separated by commas, for example referral.report_ready,referral.images_ready. |
referral_id | Only the events of one referral. |
created_after | An ISO 8601 time, to start a first sync without a cursor. |
To keep in sync:
- Start with
created_after(or no filter, for everything we keep). - Process
data, then call again withcursorset tonext_cursor, whilehas_moreistrue. - Store the last
next_cursorand continue from it next time, for example every few minutes.
A few things to know:
- The feed only returns events that are at least 30 seconds old. This guarantees nothing lands behind a cursor you've already passed. Webhooks are not delayed.
- Events are kept for 1 year. A cursor older than that returns
410 Gone; start again withcreated_after. GET /api/v1/events/:idreturns one event.webhook.testevents aren't in the feed.
Rotating the signing secret
Rotate an endpoint's secret if you've lost it, if it may have leaked, or on your own schedule:
curl https://api-sandbox.uk.scan.com/api/v1/webhook_endpoints/we_5d1e2c3b-8a4f-4b6e-9c1d-2f3a4b5c6d7e/secret_rotations \
-u "$SCAN_CLIENT_ID:$SCAN_CLIENT_SECRET" \
-H 'Content-Type: application/json' \
-d '{"previous_secret_expires_in": 86400}'- The response holds the new
secret, shown this once. You can send your ownsecretin thewhsec_format instead. - The old secret keeps working for
previous_secret_expires_inseconds: 24 hours by default, 7 days at most. Meanwhile every request carries two signatures, one per secret, so you can switch your receiver to the new secret with no gap. - If the old secret leaked, send
"previous_secret_expires_in": 0to stop it at once.
Deliveries, resending and recovery
A delivery is one event sent to one endpoint. Each try at sending it is an attempt.
| Call | What it does |
|---|---|
GET /api/v1/webhook_endpoints/:id/deliveries | The endpoint's deliveries, newest first, with a cursor. Filters: status (pending, succeeded or failed), trigger (automatic, recovery or test), event_id, created_after. limit is 50 by default, 100 at most. |
GET /api/v1/webhook_endpoints/:id/deliveries/:delivery_id | One delivery with its attempts: when, the HTTP status you answered, how long it took, any error (timeout, DNS, TLS, blocked address) and the first 1 KB of your response body. |
attempts_count counts the tries in the current run of retries. A resend or a recovery starts a new run, so attempts_count goes back to 0, while attempts keeps every try. A delivery that failed 4 times and was then resent once shows attempts_count: 1 next to 5 attempts.
We keep deliveries and attempts for 1 year. The response body excerpt is cleared after 30 days.
Resend one delivery
POST /api/v1/webhook_endpoints/:id/deliveries/:delivery_id/attempts sends a delivery again now, whatever its state. It has the same webhook-id, with a new timestamp and signature. If it fails, the normal retries start again.
Recover everything since a time
POST /api/v1/webhook_endpoints/:id/recoveries with a since time sends this endpoint every event since then that matches its event_types and hasn't already reached it successfully: failed deliveries, and events missed while the endpoint was disabled or before it existed.
curl https://api-sandbox.uk.scan.com/api/v1/webhook_endpoints/we_5d1e2c3b-8a4f-4b6e-9c1d-2f3a4b5c6d7e/recoveries \
-u "$SCAN_CLIENT_ID:$SCAN_CLIENT_SECRET" \
-H 'Content-Type: application/json' \
-d '{"since": "2026-11-20T00:00:00Z"}'- The response tells you how many events it will send.
sincemust be within the last year.- One recovery runs at a time per endpoint, and it sends at most 10,000 events. For a longer gap, start another recovery from the last event you received once the first has finished.
Testing on the sandbox
- Create an endpoint on the sandbox and store its secret.
- Send a test event with
POST /api/v1/webhook_endpoints/:id/test_events. It sends a signedwebhook.testto that endpoint only, the same way as real events, so you can check your verification code. The response is the delivery, so you can see what your receiver answered. You can send up to 10 test events a minute per endpoint. - Create a referral and move it along with the sandbox endpoints, using the user's bearer token:
/api/v1/referrals/:id/sandbox/booking,/completion,/holdand/scan_images. Each step sends realreferral.status_changed,referral.report_readyandreferral.images_readyevents, exactly as production would. - Check the deliveries with
GET /api/v1/webhook_endpoints/:id/deliveriesto see what we sent and what your receiver answered. - Try the feed with
GET /api/v1/events. - Before going live, create your production endpoint and send it a test event too. Test events work in production as well.
FAQ
Can we allowlist the IP addresses you send from?
No. Scan.com doesn't send from fixed IP addresses. Verify the signature on every request instead: that is what proves a request came from us.
What about changes after a referral is closed?
We stop recording events 30 days after a referral is Completed or Cancelled (see when events stop). Poll GET /api/v1/referrals sorted by updated_at for anything later.
Do we have to use webhooks?
No. You can use the events feed alone, or keep polling GET /api/v1/referrals.
Why doesn't the event include the patient's details or the report?
So that personal data never travels in a webhook, and a mistyped URL can't leak it. Fetch the details with the API, which checks who is asking.
Can we get one URL per referral, as a callback?
No. Endpoints belong to your organisation and receive events for all your referrals. Use referral_id or internal_reference in the event to route it.
Updated about 1 hour ago
