Guides

Receive webhooks

Build an endpoint for TimeSubmit webhooks: register it, verify each signature with a library or by hand, drop duplicates and handle retries.

A webhook endpoint is an HTTPS address on your side that TimeSubmit posts an event to as soon as a timesheet or an invoice moves. This guide builds one: register it, check each delivery's signature, drop duplicates and cope with retries. The webhooks reference lists every event type and the delivery rules in one place.

Register an endpoint

A consultancy admin adds the endpoint under Settings, then API & Webhooks:

  1. Enter its full address, starting https://. It must be reachable on the public internet.
  2. Choose the event types it should receive.
  3. Copy the signing secret. It starts whsec_ and is shown once, so store it with your other secrets straight away.

An organisation can register up to 10 endpoints, each with its own secret.

What a delivery looks like

Each delivery is a POST with the event as its JSON body, and three headers:

  • webhook-id: the event's id, the same on every retry.
  • webhook-timestamp: when this attempt was signed, in seconds since 1970.
  • webhook-signature: v1, followed by a base64 HMAC-SHA256.
{
  "id": "jd7f2kq9w4c8x1v6b3n5m0p2r",
  "type": "invoice.sent",
  "occurredAt": "2026-11-30T09:15:02.118Z",
  "data": { "id": "k1m8s4t2w6y0z3a5c7e9g1h4j" }
}

The event names the record and nothing more. To see what changed in an invoice, read it with GET /invoices/{id} and your own key. Timesheets can't be read through /v1 yet, so a timesheet. event tells you only that the timesheet moved, and which way.

Verify the signature with a library

Deliveries follow the Standard Webhooks specification, so any of its libraries can check them. Verify the raw body exactly as it arrived: if your framework parses the JSON first, the bytes change and the signature fails.

import { Webhook } from "svix"; // or any Standard Webhooks library

const webhook = new Webhook(process.env.TIMESUBMIT_WEBHOOK_SECRET); // whsec_...

export async function POST(request) {
  const body = await request.text(); // the raw body
  let event;
  try {
    event = webhook.verify(body, {
      "webhook-id": request.headers.get("webhook-id"),
      "webhook-timestamp": request.headers.get("webhook-timestamp"),
      "webhook-signature": request.headers.get("webhook-signature"),
    });
  } catch {
    return new Response("Invalid signature", { status: 400 });
  }
  await queueForProcessing(event); // your own queue
  return new Response(null, { status: 204 });
}

The library also refuses a timestamp too far from your clock, so an old delivery can't be replayed.

Verify the signature by hand

Without a library, the check takes four steps:

  1. Take the secret after whsec_ and base64-decode it.
  2. Compute an HMAC-SHA256 with it over {webhook-id}.{webhook-timestamp}.{body}, using the raw body, and base64-encode the result.
  3. Compare it, in constant time, with each v1, value in the signature header. The header can hold more than one, separated by spaces.
  4. Reject a timestamp more than five minutes from your clock.
import base64, hashlib, hmac, time

def verify(secret: str, headers: dict, body: bytes) -> bool:
    msg_id = headers["webhook-id"]
    timestamp = headers["webhook-timestamp"]
    if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 5 * 60:
        return False
    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f"{msg_id}.{timestamp}.".encode() + body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
    for part in headers["webhook-signature"].split(" "):
        version, _, signature = part.partition(",")
        if version == "v1" and hmac.compare_digest(signature, expected):
            return True
    return False

Answer quickly, then do the work

Answer with any 2xx status within 10 seconds. Anything slower counts as a failure and is sent again. Verify the signature, put the event on your own queue, answer, and do the slow part (reading the record, updating your systems) afterwards.

Drop duplicates

A delivery can arrive more than once, for example when your answer was lost on the way back. webhook-id is the event's id and stays the same on every retry, so record each id you have handled and skip one you have seen before. Deliveries can also arrive out of order, so read the record when you handle an event and act on what it says now.

Retries and a failing endpoint

A delivery that does not get a 2xx answer is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours: 7 attempts over about 21 hours. After the last attempt the delivery has failed and the endpoint is marked as failing on the settings page. The mark clears with its next successful delivery.

When an endpoint has been down for longer than the retries last, its missed events are still in the event log. Sync with events to catch up from the last one you handled.