Skip to content
Developer docsWebhooks

Guide

Webhooks

Webhooks tell your system when something changes in your organisation, so you do not have to poll. Every message is signed following the Standard Webhooks specification.

Add an endpoint

Create one with POST /v1/orgs/{orgId}/webhooks and the webhooks:manage scope, or on the portal’s Developers page.

Shell
curl -X POST https://api.wristworkout.com/v1/orgs/org_id/webhooks \
  -H "Authorization: Bearer $WW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/hooks/wrist-workout",
    "events": [
      "programme.assigned",
      "programme.unassigned",
      "customer.linked",
      "customer.unlinked"
    ],
    "description": "Booking system"
  }'
  • The address must be https on port 443, with a host name: no IP address, no user name or password, nothing on wristworkout.com, and at most 2,048 characters.
  • events lists the event types to receive, or ["*"] for all of them.
  • An organisation can have 10 endpoints.
  • The response holds the signing secret, whsec_…, this once. Store it with your other secrets.

Events

  • programme.assigned

    You assigned a programme to a customer. One message per customer the request assigned.

    dataorganisationIdprogrammeIdcustomerId

  • programme.unassigned

    An assignment ended: you unassigned it or archived the programme, the link ended, or the customer removed it from their list. by is organisation or customer; a customer deleting their account reads as customer.

    dataorganisationIdprogrammeIdcustomerIdby

  • programme.updated

    A new revision of a library programme, published by your organisation or by a customer allowed to edit it. by says which.

    dataorganisationIdprogrammeIdrevby

  • programme.copied

    A customer copied one of your programmes. programmeId is yours; the copy belongs to the customer.

    dataorganisationIdprogrammeIdcustomerId

  • customer.linked

    Someone accepted a customer invitation.

    dataorganisationIdcustomerId

  • customer.unlinked

    A link ended: the customer left or deleted their account, or your organisation unlinked them. by says which.

    dataorganisationIdcustomerIdby

  • customer.sharing_changed

    A customer saved their workout sharing choice, even if it did not change. shareResults is the current setting.

    dataorganisationIdcustomerIdshareResults

  • session.completed

    A customer who shares workouts with you uploaded a workout on one of your programmes.

    dataorganisationIdcustomerIdsessionIdprogrammeId

  • ping

    A test you started. It goes only to the endpoint you tested.

    dataorganisationIdendpointId

Payload

Every message is a JSON object with three fields: type, timestamp (when the change happened, in UTC) and data. Data holds IDs and values such as rev, never names, loads or heart rate: fetch what you need through the API with your key.

HTTP
POST /hooks/wrist-workout HTTP/1.1
Host: example.com
Content-Type: application/json
User-Agent: WristWorkout-Webhooks/1
webhook-id: msg_2f9b4c1d8e7a6053b1c2d3e4f5a6b7c8
webhook-timestamp: 1795945267
webhook-signature: v1,a6yP0ESg9Jp7B+A+fN8bwhRxWdmXbmonW5KeAyplqJU=

{"type":"programme.assigned","timestamp":"2026-11-29T09:41:07Z","data":{"organisationId":"q3Hn8VbT2kLm","programmeId":"p7Kd2LmQ9xTe","customerId":"c4Rt8NwZ1bYs"}}

The body arrives on one line, as above. Laid out for reading:

JSON
{
  "type": "programme.assigned",
  "timestamp": "2026-11-29T09:41:07Z",
  "data": {
    "organisationId": "q3Hn8VbT2kLm",
    "programmeId": "p7Kd2LmQ9xTe",
    "customerId": "c4Rt8NwZ1bYs"
  }
}
  • organisationId is in every message. customerId is the customer’s ID in your organisation, the same id the customer routes use.
  • webhook-id is the message’s ID: msg_ and 32 hexadecimal characters, the same on every attempt.
  • webhook-timestamp is when this attempt was sent, in Unix seconds. It changes on each retry; timestamp in the body does not.

Verify the signature

Check every message before you act on it:

  1. Read the raw request body as text. Parse it as JSON only after the check.
  2. Join webhook-id, webhook-timestamp and the body with . between them.
  3. Compute an HMAC-SHA256 of that text. The key is the secret’s bytes: the part after whsec_, decoded from base64.
  4. Compare the result, in base64, with each v1, entry in webhook-signature. Entries are separated by spaces. Compare in constant time.
  5. Refuse a message whose webhook-timestamp is more than 5 minutes from your clock.

headers below is a Fetch Headers object, as in Workers, Deno, Bun and Node's own fetch. With Express, pass new Headers(req.headers), and read the body raw with express.raw({ type: 'application/json' }).

verify-webhook.jsJavaScript
// Verifies a Wrist Workout webhook: Standard Webhooks, signature v1.
// Web Crypto is built into Node 20 and later, Deno, Bun and Workers.
const TOLERANCE_SECONDS = 5 * 60;

export async function verifyWebhook(secret, headers, body) {
  const id = headers.get('webhook-id');
  const timestamp = headers.get('webhook-timestamp');
  const signatures = headers.get('webhook-signature');
  if (!id || !timestamp || !signatures) return false;

  // An old or future timestamp could be a captured message sent again.
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (!(age <= TOLERANCE_SECONDS)) return false;

  const raw = fromBase64(secret.replace(/^whsec_/, ''));
  if (!raw) return false;
  const key = await crypto.subtle.importKey(
    'raw',
    raw,
    { name: 'HMAC', hash: 'SHA-256' },
    false,
    ['verify'],
  );
  const signed = new TextEncoder().encode(`${id}.${timestamp}.${body}`);
  for (const entry of signatures.split(' ')) {
    const [version, value] = entry.split(',');
    const signature = version === 'v1' && value && fromBase64(value);
    if (!signature) continue;
    // verify() compares in constant time.
    const ok = await crypto.subtle.verify('HMAC', key, signature, signed);
    if (ok) return true;
  }
  return false;
}

function fromBase64(text) {
  try {
    return Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
  } catch {
    return null;
  }
}
Using it in a Cloudflare WorkerJavaScript
export default {
  async fetch(request, env) {
    const body = await request.text();
    const secret = env.WW_WEBHOOK_SECRET;
    if (!(await verifyWebhook(secret, request.headers, body))) {
      return new Response('invalid signature', { status: 400 });
    }
    // Hand the event to a queue and answer straight away.
    await env.EVENTS.send({
      id: request.headers.get('webhook-id'),
      event: JSON.parse(body),
    });
    return new Response(null, { status: 204 });
  },
};

The Standard Webhooks libraries verify these messages as they are: give them the whsec_… secret, the headers and the raw body.

To test your code, check that it accepts the message in Payload with this example secret, with the timestamp check turned off. The secret is an example and works nowhere else:

Text
whsec_3GeioP/tKgw4GsDAU0stjTes/w5hapuWnpc5V7BljFM=

Answer and retries

  • Answer with any 2xx status within 15 seconds. If the work takes longer, queue it and answer first.
  • Any other status, a redirect, a timeout or a network error counts as a failure. Wrist Workout follows no redirects and ignores what your answer contains.
  • Straight after a change, the API sends up to 20 of your organisation’s waiting messages, oldest first. The rest wait for a job that runs every 15 minutes and sends up to 50 waiting messages, across all organisations, each time. A change that raises many messages at once, such as assigning a programme to 100 customers, can take a while to arrive in full.
  • A failed message is retried 5 minutes, 30 minutes, 2 hours and 5 hours later, then every 10 hours, for up to 3 days. Retries go with the same job, so a retry can leave a little after its due time.
  • An endpoint that has failed for 3 days is disabled, and the portal shows it as disabled. While it is, no new messages are queued for it. Turn it back on with PATCH /v1/orgs/{orgId}/webhooks/{endpointId} and {"enabled": true}, or in the portal. Catching up says what it missed.
  • GET /v1/orgs/{orgId}/webhooks/{endpointId}/deliveries lists the last 30 days of messages with their state, attempts and last status.

Paused endpoints

An organisation without a plan of its own that includes webhooks has its endpoints paused:

  • paused is true on each of its endpoints, whether or not the endpoint is turned on.
  • Changes raise no messages for a paused endpoint. Messages queued before the pause still go out.
  • Adding an endpoint, turning one back on and sending a test event get 403 FORBIDDEN with the reason plan_required. Listing, changing, turning off and deleting endpoints still work.
  • Once the organisation has a plan that includes webhooks, its endpoints resume by themselves. Changes made while they were paused are never sent, so catch up then.

Catching up after failures

Some messages never arrive:

  • A message that has not got through within 3 days of its change is marked failed, and is not tried again.
  • While an endpoint is turned off or paused, changes raise no messages for it, and nothing sends them later.

No route resends a message. The deliveries list shows each message’s id (its webhook-id), eventType, state, attempts and times, but not its data. Messages still waiting when an endpoint was turned off are tried again once it is back on.

To notice trouble early, read GET /v1/orgs/{orgId}/webhooks now and then. failingSince is when an endpoint started failing, and goes back to null after a success or when you turn the endpoint back on. enabled is false while it is turned off, and paused is true while the organisation’s plan holds its endpoints back.

After an endpoint was failing, turned off or paused, read again what your system keeps a copy of: GET /v1/orgs/{orgId}/customers, with each customer’s shareResults; GET /v1/orgs/{orgId}/assignments; GET /v1/orgs/{orgId}/programmes; and, for each customer who shares workouts, GET /v1/orgs/{orgId}/customers/{customerId}/sessions.

Handle each message once

A message can arrive more than once, for example when your server did the work but answered after the 15 seconds. webhook-id is the same on every attempt of a message, so:

  • record each webhook-id you handle, for at least 3 days, and skip one you have seen;
  • or make each handler safe to repeat, for example by setting a state rather than adding to a count.

Messages can also arrive out of order, for example when a retry follows a newer message. Order them by timestamp, or fetch the current state through the API.

Test an endpoint

POST /v1/orgs/{orgId}/webhooks/{endpointId}/test sends a signed ping to the endpoint now and returns the result: the message’s ID, its state and the status your endpoint answered (lastStatus: 0 when there was no answer, null when the ping was not sent). The test first sends up to 10 of the endpoint’s older waiting messages, so with a backlog the ping can come back pending and go out after them. A disabled endpoint is not called: the ping waits, pending, until you turn the endpoint back on. A paused endpoint gets no test: the request gets 403 with the reason plan_required.

Change a secret

A secret cannot be changed in place. To move to a new one:

  1. Add a second endpoint with the same address and events. It gets its own secret.
  2. Let your receiver accept messages signed with either secret.
  3. Delete the old endpoint, then remove its secret from your receiver.

While both endpoints exist, each event is sent to both, with a different webhook-id from each. Treat the two as one event, for example by comparing type, timestamp and data.