Webhooks
Receive the outcome of cloud sessions and video jobs on your server, verify it, and handle it once.
Webhooks deliver the outcome of cloud work to your server as soon as it is known, so you do not have to poll.
Two kinds
| Organization endpoint | Per-job webhookUrl | |
|---|---|---|
| Set up | Console → Webhooks, up to 5 per organization | webhookUrl in POST /sdk/v1/cloud/jobs |
| Receives | Every cloud job of the organization: live cloud sessions and video jobs | That video job only |
| Body | Event envelope with id and event | { "ok": true, "data": … }, same as GET /sdk/v1/cloud/jobs/{jobId} |
| Signed with | The endpoint's secret, whsec_… | Your API key |
Both kinds fire independently. If you use both, a video job reaches you once through each.
Organization endpoints
Add an endpoint in Console → Webhooks. The URL must use https on a public host; the host is
checked again at every delivery. The console shows the endpoint's whsec_… secret once; store
it on your server. Rotating the secret issues a new one.
Events
| Event | Sent when |
|---|---|
cloud.job.completed | The measurement is ready. data.measurement holds it |
cloud.job.failed | Processing failed. data.error.code says why |
cloud.job.aborted | The session ended without a result, for example the connection dropped |
cloud.job.expired | The uploaded video expired before processing |
webhook.test | You sent a test event from the console. data is a placeholder job without a measurement |
Job error codes are listed in Errors.
When the live connection drops and the SDK finishes a session by upload, the result arrives as a
separate job: cloud.job.completed with a new jobId, data.mode: "batch_frames", the
measurement and the session's userRef. Its data.supersedes holds the original session ID,
so match the result to your session by data.supersedes ?? data.jobId. The session itself, read
with GET /sdk/v1/cloud/jobs/{sessionId}, shows error.code: "superseded" and
supersededBy.jobId.
With a test key, video jobs send events with data.isTest: true. Test cloud sessions send none.
Payload
{
"id": "whd_7d3e91c04a5b28f6e1c0b9a2",
"event": "cloud.job.completed",
"createdAt": 1790000062000,
"data": {
"jobId": "cj_4b7e2d05138b6a37f429c1f4",
"keyId": "nk_live_sRwG9z2hK2hdV4Il83J7Cw",
"mode": "stream",
"status": "completed",
"platform": "web",
"isTest": false,
"createdAt": 1790000000000,
"startedAt": 1790000001500,
"finishedAt": 1790000061800,
"secondsProcessed": 60,
"measurementId": "meas_9c1f4b7ae2d05138b6a37f42",
"userRef": "u_42",
"measurement": {
"id": "meas_9c1f4b7ae2d05138b6a37f42",
"origin": "cloud",
"attested": true,
"quality": { "level": "good", "score": 0.82, "usable": true },
"cardiac": { "heartRate": { "value": 72, "unit": "bpm", "confidence": 0.88 } }
}
}
}| Field | Type | Description |
|---|---|---|
id | string | Delivery ID, whd_…. Matches the row in the console's delivery journal |
event | string | One of the events above |
createdAt | number | When the delivery was created, epoch milliseconds |
data | object | The job, as GET /sdk/v1/cloud/jobs/{jobId} returns it. measurement is the full measurement result when the job completed |
data.mode is stream for a live session, batch_video for a video job, and batch_frames
for a job the SDK created to finish a live session by upload. On such a job, the read-only
data.supersedes holds the original session ID; on other jobs it is null.
Headers
| Header | Value |
|---|---|
content-type | application/json |
x-webhook-id | Endpoint ID, wh_… |
x-timestamp | Unix time in seconds when the attempt was sent |
x-nonce | Random string, new for every attempt |
x-signature | Base64 HMAC-SHA256 of the canonical string |
Signature
Deliveries are signed with the same scheme as your API requests:
NCS1
POST
{path of your webhook URL, without the query string}
{x-timestamp}
{x-nonce}
{SHA-256 of the raw body, lowercase hex}The HMAC key is the lowercase hex SHA-256 of the whsec_… secret. Verify against the raw body
before you parse it, and reject deliveries whose timestamp is more than 5 minutes old.
import crypto from 'node:crypto';
import express from 'express';
const WEBHOOK_PATH = '/webhooks/neccessory';
const WEBHOOK_SECRET = process.env.NECCESSORY_WEBHOOK_SECRET;
const TOLERANCE_SEC = 300;
const sha256Hex = (data) => crypto.createHash('sha256').update(data).digest('hex');
export function verifyNcs1({ secret, path, headers, rawBody }) {
const timestamp = headers['x-timestamp'];
const nonce = headers['x-nonce'];
const signature = headers['x-signature'];
if (!timestamp || !nonce || !signature) return false;
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!Number.isFinite(age) || age > TOLERANCE_SEC) return false;
const canonical = ['NCS1', 'POST', path, timestamp, nonce, sha256Hex(rawBody)].join('\n');
const expected = crypto.createHmac('sha256', sha256Hex(secret)).update(canonical).digest();
const received = Buffer.from(signature, 'base64');
return received.length === expected.length && crypto.timingSafeEqual(received, expected);
}
const processed = new Set();
function handleJob(event, job) {
const sessionId = job.supersedes ?? job.jobId;
if (event === 'cloud.job.completed') {
console.log('measurement ready', sessionId, job.measurementId, job.userRef);
} else {
console.log('job ended without a result', sessionId, job.error?.code);
}
}
const app = express();
app.post(WEBHOOK_PATH, express.raw({ type: 'application/json', limit: '1mb' }), (req, res) => {
const valid = verifyNcs1({
secret: WEBHOOK_SECRET,
path: WEBHOOK_PATH,
headers: req.headers,
rawBody: req.body,
});
if (!valid) return res.sendStatus(401);
const delivery = JSON.parse(req.body.toString('utf8'));
const dedupeKey = `${delivery.data.jobId}:${delivery.event}`;
if (delivery.event !== 'webhook.test' && !processed.has(dedupeKey)) {
processed.add(dedupeKey);
setImmediate(() => handleJob(delivery.event, delivery.data));
}
res.sendStatus(204);
});
app.listen(3000);Sign against the path of the URL you registered, not the path your framework sees: a reverse proxy can rewrite it. In production, keep the dedupe keys in your database instead of memory.
Delivery rules
| Rule | Value |
|---|---|
| Attempts | Up to 3 per delivery |
| Backoff | 1 s before the second attempt, 2 s before the third |
| Timeout | 10 s per attempt |
| Success | Any 2xx status. Anything else, a timeout or a connection error fails the attempt |
| Redirects | Not followed. A 3xx fails the attempt |
| Target | https on a public host, checked at every delivery |
| Signing | Every attempt is signed anew with a fresh timestamp and nonce |
Handle deliveries once
- Automatic retries resend the same body with the same
id. - A redelivery from the console is rebuilt from the job's current state and gets a new
id. - Deduplicate on
data.jobIdtogether withevent. This covers both cases. - Respond with
2xxright away and process the job afterwards. Slow handlers hit the 10 s timeout and trigger retries. - If every attempt fails, read the job with
GET /sdk/v1/cloud/jobs/{jobId}or redeliver it from the console.
Journal, redelivery and test events
Console → Webhooks keeps a delivery journal for each endpoint: event, status, HTTP code, attempts, error and response time. From there you can:
- redeliver a single delivery, retry all failed deliveries on the page, or redeliver a job by its ID;
- send a
webhook.testevent to check your receiver end to end; - rotate the secret. The new secret is shown once. To switch without failed deliveries, let your receiver accept both the old and the new secret until the switch is done.
Per-job webhookUrl
Pass webhookUrl when you create a video job with POST /sdk/v1/cloud/jobs. It must use
https on a public host, otherwise the request fails with 400 validation_error. See
Video processing.
When the job ends (completed, failed, aborted or expired), Neccessory sends a POST with the
same body that GET /sdk/v1/cloud/jobs/{jobId} returns:
{
"ok": true,
"data": {
"jobId": "cj_58e2a1c7d90b4f36a2e81c05",
"mode": "batch_video",
"status": "completed",
"measurementId": "meas_2d7f0c9e4b1a86d35f0e7a21",
"measurement": { "id": "meas_2d7f0c9e4b1a86d35f0e7a21", "origin": "cloud", "attested": true }
}
}There is no event field: read data.status. Delivery rules are the same as for organization
endpoints.
The request is signed with your API key. The headers are content-type, x-key-id (your key
ID), x-timestamp, x-nonce and x-signature, and the canonical string uses POST and the
path of your webhookUrl. Verify it with the function above and your API secret:
const valid =
req.headers['x-key-id'] === process.env.NECCESSORY_KEY_ID &&
verifyNcs1({
secret: process.env.NECCESSORY_SECRET,
path: '/webhooks/neccessory-jobs',
headers: req.headers,
rawBody: req.body,
});