> ## Documentation Index
> Fetch the complete documentation index at: https://partners.usehammock.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Events and webhooks

> Hammock records an event for every change and delivers it to your webhook endpoints.

Most of what happens in Hammock isn't started by your API calls. An employee enrolls, changes a
contribution or has a claim approved; a pull settles; an employer passes review. Each of those
creates an event, and Hammock delivers it to your webhook endpoints.

## Thin events

Events are thin. An event says what happened and which object it happened to, and doesn't carry a
copy of the object.

```json theme={null}
{
  "id": "evt_9Qw2Er5tYu8I",
  "object": "event",
  "type": "deduction.updated",
  "created": "2027-03-18T16:42:11Z",
  "livemode": true,
  "employer": "empr_1Qx8Zt2eZvKYlo2C",
  "related_object": {
    "id": "ded_2Lp9Xc4vNm7K",
    "type": "deduction",
    "url": "/deductions/ded_2Lp9Xc4vNm7K"
  },
  "request": null
}
```

When you receive one, retrieve `related_object.url` to read the object as it is now. This has
three advantages:

* **You always act on current state.** A delayed or out-of-order delivery can't overwrite newer
  data with older data.
* **No personal data in transit.** Deliveries contain IDs only, so nothing sensitive sits in your
  request logs or queues.
* **No payload versions.** The object comes back in the API version your code asks for.

`request` is set when one of your own API calls caused the event, and holds its request ID and
idempotency key.

## Set up an endpoint

```bash theme={null}
curl https://api.usehammock.co/webhook_endpoints \
  -H "Authorization: Bearer hmk_live_..." \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 61a50c33-7587-4268-86c4-0a2c5043311d" \
  -d '{
    "url": "https://partner.example/webhooks/hammock",
    "enabled_events": ["*"]
  }'
```

The response includes the endpoint's signing `secret`, which starts with `whsec_`. This is the
only time it's returned, so store it. `enabled_events` takes [event types](https://partners.usehammock.co/webhooks/event-types.md),
or `["*"]` for all of them. One endpoint receives events for all your employers; use the event's
`employer` field to route them.

## Handle a delivery

Hammock sends each event as a `POST` with a JSON body and a `Hammock-Signature` header.

**1. Verify the signature**

Check the `Hammock-Signature` header against the raw request body before you trust it. See
[verify signatures](https://partners.usehammock.co/webhooks/signatures.md).

**2. Acknowledge quickly**

Return any `2xx` status within 10 seconds. Put the event on a queue and do the work
afterwards, so a slow job doesn't turn into a failed delivery.

**3. Skip duplicates**

An event can be delivered more than once. Record the `id` of each event you process and ignore
repeats.

**4. Fetch the object**

Retrieve `related_object.url` and act on what comes back.

## Delivery behavior

| Behavior | Detail |
| - | - |
| Retries | A delivery that doesn't get a `2xx` in time is retried with exponential backoff for up to three days. The sandbox retries three times over a few hours. |
| Ordering | Not guaranteed. `deduction.updated` can arrive before `deduction.created`. Fetching the object makes order irrelevant. |
| Duplicates | Possible. Deduplicate on the event `id`. |
| Failures | If an endpoint fails for several days, Hammock disables it and emails you. Re-enable it by updating its `status`. |

## Catch up after downtime

Events are kept for 30 days. If your endpoint was down, list what you missed:

```bash theme={null}
curl "https://api.usehammock.co/events?created_after=2027-03-18T00:00:00Z&limit=100" \
  -H "Authorization: Bearer hmk_live_..."
```

A periodic reconciliation is also worth having: before each payroll, read
[deductions](https://partners.usehammock.co/guides/deductions.md) for the pay date and pending
[reimbursements](https://partners.usehammock.co/guides/reimbursements.md) directly, so a missed event can never put a wrong amount
on a paycheck.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.