# Webhooks

How TimeSubmit sends signed webhooks for timesheet, invoice and purchase order events: event types, delivery, retries and verifying a signature.

## Endpoints

A consultancy admin can register up to 10 HTTPS endpoints under Settings, then API & Webhooks, each with the event types it wants. The endpoint's signing secret starts `whsec_` and is shown once, when you add it.

## Event types

Each event is sent to every endpoint that asked for its type.

| Type | Recorded when |
| --- | --- |
| `timesheet.submitted` | A consultant submitted a timesheet for approval. |
| `timesheet.approved` | A timesheet was finally approved, once: by a consultancy admin, by its last approver where the consultancy has chosen that, or by an admin override. An approver signing off a step that is not the last is not this event. |
| `timesheet.rejected` | A timesheet was rejected, by an admin or by one of its approvers. |
| `invoice.raised` | An invoice was raised, of either kind. A consultant's time in more than one currency is raised as one payable per currency, each with its own event. |
| `invoice.sent` | An invoice was marked as sent. |
| `invoice.paid` | An invoice was marked as paid. |
| `invoice.discarded` | An invoice was discarded. |
| `invoice.rejected` | The consultancy rejected a consultant's invoice it had been sent, with a reason. Its weeks can be invoiced again. |
| `client_purchase_order.created` | A client purchase order was recorded. |
| `client_purchase_order.changed` | A client purchase order's number, dates, budget or projects were changed. |
| `client_purchase_order.closed` | A client purchase order was closed. |
| `client_purchase_order.deleted` | A client purchase order was deleted. Its id no longer reads. |
| `client_purchase_order.budget_near` | Invoiced plus committed on a client purchase order reached the consultancy's nearly-used percentage of its budget, 85% unless the consultancy changed it. Recorded once by the daily check, and again after its budget is changed, or after the consultancy changes its nearly-used percentage while the purchase order is past the new one. |
| `client_purchase_order.budget_used` | A client purchase order reached 100% of its budget, invoiced plus committed. Recorded once by the daily check, and again only after its budget is changed. A change of the nearly-used percentage never repeats it. |
| `client_purchase_order.ending` | A client purchase order is 30 days or fewer from its end date. Recorded once by the daily check, and again only after its end date is changed. |
| `consultant_purchase_order.created` | A consultant purchase order was recorded. |
| `consultant_purchase_order.changed` | A consultant purchase order's number, dates, budget or assignments were changed. |
| `consultant_purchase_order.closed` | A consultant purchase order was closed. |
| `consultant_purchase_order.deleted` | A consultant purchase order was deleted. Its id no longer reads. |
| `consultant_purchase_order.budget_near` | Invoiced plus committed on a consultant purchase order reached the consultancy's nearly-used percentage of its budget, 85% unless the consultancy changed it. Recorded once by the daily check, and again after its budget is changed, or after the consultancy changes its nearly-used percentage while the purchase order is past the new one. |
| `consultant_purchase_order.budget_used` | A consultant purchase order reached 100% of its budget, invoiced plus committed. Recorded once by the daily check, and again only after its budget is changed. A change of the nearly-used percentage never repeats it. |
| `consultant_purchase_order.ending` | A consultant purchase order is 30 days or fewer from its end date. Recorded once by the daily check, and again only after its end date is changed. |

This list can grow within `/v1`, so ignore any you don't recognise rather than failing on it. See [versioning](https://www.timesubmit.com/developers/versioning).

## Delivery

Each delivery is a POST whose body is the event: its id, its type, when it happened and the id of the record it happened to. Read the record through the API to see what changed. The [events reference](https://www.timesubmit.com/developers/reference/events) describes each field.

```json
{
  "id": "jd7f2kq9w4c8x1v6b3n5m0p2r",
  "type": "invoice.sent",
  "occurredAt": "2026-11-30T09:15:02.118Z",
  "data": { "id": "k1m8s4t2w6y0z3a5c7e9g1h4j" }
}
```

## Retries

Answer with any 2xx status within 10 seconds. Anything else, or no answer, is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours: 7 attempts over about 21 hours. An endpoint that keeps failing is marked as failing on the settings page.

Deliveries can arrive out of order and, rarely, twice, so use the event's id to drop a repeat. If your endpoint was down for longer than the retries last, catch up with `GET /events?since=` (see [events](https://www.timesubmit.com/developers/reference/events#catching-up)).

## Verifying a delivery

Deliveries are signed to the [Standard Webhooks](https://www.standardwebhooks.com) specification, so any of its libraries verifies them. [Receive webhooks](https://www.timesubmit.com/developers/receive-webhooks) builds a whole receiver, step by step. Three headers come with each delivery:

- `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.

```js
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, before any JSON parsing
  const 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"),
  }); // throws if the signature or the timestamp is wrong
  // event.type, event.data.id: fetch the record with your API key
  return new Response(null, { status: 204 });
}
```

### Without a library

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.
4. Reject a timestamp more than five minutes from your clock, so an old delivery cannot be replayed.
