Events and webhooks
Telling other systems what changed, safely.
Every change in Care Core creates an event. Webhooks deliver those events to other systems (a rota, a payroll tool, a training platform, your own scripts) as signed HTTP requests, so they can react to a joiner, mover or leaver without polling Care Core and without anyone telling them.
How it works
- When something changes, an event is written to the outbox in the same transaction as the change. An event can never be lost, and never exists for a change that rolled back.
- A background job (
scripts/deliver-events.php, run every minute) matches each new event to the webhook endpoints that want it and sends it. - If the receiver fails, the delivery is retried with increasing gaps.
Events are delivered at least once. Your receiver must therefore tolerate seeing the same event twice, using the event id as an idempotency key.
Prefer polling, or want to manage webhooks from your own deployment scripts? The API has an event feed (GET /events) with the same events, and endpoints to create and inspect webhooks.
Adding a webhook
Administrators: Admin › Integrations › Webhooks. Enter the URL (must be https://) and the event types you want, then choose Add. Care Core shows the signing secret once: copy it and store it where your receiver can read it. You can pause and resume an endpoint, and the page shows, for each address, how many events were delivered and how many are waiting or failed, plus the latest events and whether each has been queued for delivery.
Choosing event types
*(the default): everything.- A prefix with a star:
employment.*matchesemployment.started,employment.changedandemployment.ended. - Exact names, separated by commas:
employment.started,employment.ended.
The full list is in the event catalogue.
Address rules
The address must be https (plain http is allowed only for localhost while developing), must not contain a username or password, and must not point at link-local or internal metadata addresses. This stops a webhook being used to probe your own network.
What a delivery looks like
POST /your/endpoint HTTP/1.1
Content-Type: application/json
User-Agent: CareCore-Webhook/1
X-CareCore-Event: employment.ended
X-CareCore-Event-Id: 7f1c2a54-9b0e-4c43-8d1a-3d9f7c1d2e10
X-CareCore-Attempt: 1
X-CareCore-Signature: sha256=3b1d… (hex HMAC)
{
"id": "7f1c2a54-9b0e-4c43-8d1a-3d9f7c1d2e10",
"type": "employment.ended",
"version": 1,
"occurred_at": "2026-11-12T09:30:00.123Z",
"organisation": "c0a8…",
"subject": "5a41…",
"data": { "employment": "9be2…", "end_date": "2026-11-12", "reason": "Resigned" }
}
| Field | Meaning |
|---|---|
id | Unique id of this event. Use it to de-duplicate. |
type | What happened, for example employment.ended. |
version | Envelope version. Currently 1. New fields may be added within a version; existing ones will not change meaning. |
occurred_at | UTC time with milliseconds. |
organisation | The organisation’s UUID. |
subject | The UUID of the person the event is about (or of the team, for team events). |
data | Identifiers and dates, specific to the type. |
Verifying the signature
Always verify the signature before trusting a delivery. It is a hex HMAC-SHA256 of the raw request body, using the endpoint’s secret as the key, sent as sha256=<hex>. Compare in constant time, and use the raw bytes, not a re-encoded copy of the JSON.
PHP
$body = file_get_contents('php://input');
$sent = $_SERVER['HTTP_X_CARECORE_SIGNATURE'] ?? '';
$want = 'sha256=' . hash_hmac('sha256', $body, getenv('CARECORE_WEBHOOK_SECRET'));
if (!hash_equals($want, $sent)) { http_response_code(401); exit; }
$event = json_decode($body, true);
// de-duplicate on $event['id'], then act
http_response_code(204);
Node.js (Express)
import crypto from 'node:crypto';
app.post('/carecore', express.raw({ type: 'application/json' }), (req, res) => {
const want = 'sha256=' + crypto.createHmac('sha256', process.env.SECRET).update(req.body).digest('hex');
const got = req.get('X-CareCore-Signature') || '';
if (got.length !== want.length || !crypto.timingSafeEqual(Buffer.from(got), Buffer.from(want))) return res.sendStatus(401);
const event = JSON.parse(req.body); // de-duplicate on event.id, then act
res.sendStatus(204);
});
Python (Flask)
import hmac, hashlib, os
from flask import Flask, request, abort
app = Flask(__name__)
@app.post('/carecore')
def carecore():
body = request.get_data()
want = 'sha256=' + hmac.new(os.environ['SECRET'].encode(), body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(want, request.headers.get('X-CareCore-Signature', '')):
abort(401)
event = request.get_json() # de-duplicate on event['id'], then act
return '', 204
Responding and retrying
- Reply with any 2xx status within 10 seconds to acknowledge. Do slow work afterwards, off the request.
- Anything else (a timeout, a connection error, a 4xx or 5xx) counts as a failure and is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours. After the last retry the delivery is marked failed. The
X-CareCore-Attemptheader says which try this is. - Deliveries to one endpoint are independent. A failing endpoint never holds up the others.
- Events are generally delivered in the order they happened, but retries can reorder them. Use
occurred_atif order matters, and treat the receiver as idempotent.
Good practice for receivers
- Verify the signature first; reject anything that does not verify.
- Store processed event ids and ignore repeats.
- Acknowledge quickly; queue the real work.
- Be ready for event types you do not know yet: ignore them rather than failing.
- Keep the secret out of source control. To rotate it, add a new endpoint, switch over, then pause the old one.
Running the delivery job
* * * * * php /path/to/scripts/deliver-events.php
Without this job, events accumulate safely in the outbox but nothing is sent. Run it every minute.