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

# Webhooks

> Receive End Close webhook events at your HTTPS endpoint, verify the End-Close-Signature header, and handle retries and duplicate deliveries.

End Close webhooks send an HTTPS `POST` to your server when something happens in End Close, such as a record being reconciled. Each delivery is a signed JSON event, so your systems can react without polling the API.

Webhooks are a premium feature. To turn them on, [contact End Close](mailto:founders@endclose.com).

## Set up a webhook endpoint

**1. Build a handler**

Add an HTTPS route to your app that accepts `POST` requests with a JSON body. Keep access to the raw request body, because you need the exact bytes to verify the signature.

**2. Request access**

Email [founders@endclose.com](mailto:founders@endclose.com) with your endpoint URL and the [events](https://endclose.com/docs/webhooks/events.md) you want. End Close sets up the endpoint for you.

**3. Store the signing secret**

End Close gives you a signing secret for the endpoint. It's shown once, so store it in a secrets manager or environment variable straight away.

**4. Verify every delivery**

Check the `End-Close-Signature` header on each request before you trust the payload, as described below.

## Event payload

Every delivery has the same envelope. The `data` object holds the resource the event is about.

| Field | Type | Description |
| - | - | - |
| `id` | string | Unique identifier for the event. Use it to detect duplicate deliveries. |
| `event_type` | string | The event name, such as `record.reconciled`. |
| `timestamp` | string (ISO 8601 date-time) | When the event happened. |
| `data` | object | The event's payload. For record events, a [record](https://endclose.com/docs/concepts/records.md). |

```json record.reconciled theme={"dark"}
{
  "id": "0d9b6a52-3c1e-4f7a-b8d2-6e4c0f1a9b37",
  "event_type": "record.reconciled",
  "timestamp": "2026-11-03T14:22:05Z",
  "data": {
    "id": "019a4f2e-8c1b-7d35-9e2a-4b6c1f0d3e57",
    "amount": 125000,
    "currency": "USD",
    "decimal_places": 2,
    "direction": "credit",
    "description": "Stripe payout po_1QxR2b",
    "date": "2026-11-03",
    "metadata": {},
    "external_id": "po_1QxR2b",
    "data_stream_key": "operating_account"
  }
}
```

See [Webhook events](https://endclose.com/docs/webhooks/events.md) for each event and when it fires.

## Verify the signature

End Close signs every delivery with your endpoint's signing secret and puts the result in the `End-Close-Signature` header:

```text Header theme={"dark"}
End-Close-Signature: t=1762179725,v1=5f0c3a9d2b7e41c8a6f19d0e4b3c72a8e15d6f9b0c4a7e2d1f8b3c6a9e0d4f71
```

* `t` is the time the delivery was signed, in Unix seconds.
* `v1` is the hex-encoded HMAC-SHA256 of the string `<t>.<raw request body>`, keyed with your signing secret.

To verify a delivery:

1. Split the header on `,` and read the `t` and `v1` values.
2. Reject the request if `t` is more than 5 minutes from your server's current time. This stops an attacker replaying an old delivery.
3. Build the signed string: the `t` value, a period, then the raw request body exactly as received.
4. Compute HMAC-SHA256 of that string with your signing secret and hex-encode it.
5. Compare your result with `v1` using a constant-time comparison. Reject the request if they differ.

> [!WARNING]
>
> Compute the signature over the raw body bytes. If your framework parses the JSON and you serialize it again, whitespace or key order can change and the signature won't match.

```javascript Node.js theme={"dark"}
import crypto from "node:crypto";
import express from "express";

const TOLERANCE_SECONDS = 5 * 60;

function verifyEndCloseSignature(rawBody, header, secret) {
  if (!header) return false;

  const parts = Object.fromEntries(
    header.split(",").map((part) => {
      const index = part.indexOf("=");
      return [part.slice(0, index).trim(), part.slice(index + 1).trim()];
    })
  );
  const timestamp = Number(parts.t);
  const signature = parts.v1;
  if (!Number.isInteger(timestamp) || !signature) return false;

  const age = Math.abs(Math.floor(Date.now() / 1000) - timestamp);
  if (age > TOLERANCE_SECONDS) return false;

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.${rawBody}`)
    .digest("hex");

  const a = Buffer.from(expected, "utf8");
  const b = Buffer.from(signature, "utf8");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

const app = express();

app.post(
  "/webhooks/endclose",
  express.raw({ type: "application/json" }),
  (req, res) => {
    const rawBody = req.body.toString("utf8");
    const header = req.get("End-Close-Signature");

    if (!verifyEndCloseSignature(rawBody, header, process.env.ENDCLOSE_WEBHOOK_SECRET)) {
      return res.sendStatus(400);
    }

    const event = JSON.parse(rawBody);
    // Queue the event for processing, then acknowledge.
    res.sendStatus(200);
  }
);
```

```python Python theme={"dark"}
import hashlib
import hmac
import json
import os
import time

from flask import Flask, abort, request

TOLERANCE_SECONDS = 5 * 60

def verify_end_close_signature(raw_body: bytes, header: str, secret: str) -> bool:
    if not header:
        return False

    parts = dict(part.strip().split("=", 1) for part in header.split(",") if "=" in part)
    try:
        timestamp = int(parts["t"])
        signature = parts["v1"]
    except (KeyError, ValueError):
        return False

    if abs(time.time() - timestamp) > TOLERANCE_SECONDS:
        return False

    signed = f"{timestamp}.".encode() + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature)

app = Flask(__name__)

@app.post("/webhooks/endclose")
def endclose_webhook():
    raw_body = request.get_data()
    header = request.headers.get("End-Close-Signature", "")

    if not verify_end_close_signature(raw_body, header, os.environ["ENDCLOSE_WEBHOOK_SECRET"]):
        abort(400)

    event = json.loads(raw_body)
    # Queue the event for processing, then acknowledge.
    return "", 200
```

```ruby Ruby theme={"dark"}
require "openssl"
require "rack/utils"
require "json"

TOLERANCE_SECONDS = 5 * 60

def verify_end_close_signature(raw_body, header, secret)
  return false if header.nil? || header.empty?

  parts = header.split(",").to_h { |part| part.strip.split("=", 2) }
  timestamp = Integer(parts["t"], exception: false)
  signature = parts["v1"]
  return false if timestamp.nil? || signature.nil?

  return false if (Time.now.to_i - timestamp).abs > TOLERANCE_SECONDS

  expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{timestamp}.#{raw_body}")
  Rack::Utils.secure_compare(expected, signature)
end

# In a Rails controller:
class EndCloseWebhooksController < ActionController::API
  def create
    raw_body = request.raw_post
    header = request.headers["End-Close-Signature"]

    unless verify_end_close_signature(raw_body, header, ENV.fetch("ENDCLOSE_WEBHOOK_SECRET"))
      return head :bad_request
    end

    event = JSON.parse(raw_body)
    # Queue the event for processing, then acknowledge.
    head :ok
  end
end
```

## Respond quickly

Return a `2xx` status as soon as you've verified and stored the event. Do slow work, such as updating your ledger or calling other APIs, in a background job after you respond.

## Retries and duplicate deliveries

When a delivery fails, End Close retries it with exponential backoff. Because of retries, your endpoint can receive the same event more than once.

Make your handler idempotent: record each event's `id` when you process it, and skip any event whose `id` you've already handled.

## FAQ

> [accordion] How do I get webhooks turned on?
>
> Webhooks are a premium feature. Email [founders@endclose.com](mailto:founders@endclose.com) with your endpoint URL and the events you want, and End Close sets up the endpoint and sends you its signing secret.

> [accordion] Why does my signature check fail?
>
> The most common cause is signing a re-serialized body instead of the raw bytes. Also check that you're using the secret for this endpoint, that you include the `t` value and the period in the signed string, and that your server clock is accurate to within 5 minutes.

> [accordion] Can the same event arrive twice?
>
> Yes. Retries mean a delivery can repeat. Deduplicate on the event `id`.

## Related

> [card] [Webhook events](https://endclose.com/docs/webhooks/events.md)
>
> Every event End Close sends, with example payloads.

> [card] [Records](https://endclose.com/docs/concepts/records.md)
>
> The record object that record events carry.


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