ac-co.ai docs

Webhooks

Subscribe to lead.created, opportunity.stage_changed, form.submitted, submission.accepted and submission.rejected events, and verify delivery signatures.

The Public API can push events to your own HTTPS endpoint instead of you polling for them. Manage subscriptions with webhooks:read / webhooks:write scopes; see API Reference for full request/response schemas.

Managing webhooks is an organisation admin action: the API key (or session) must belong to an owner or admin of the organisation. Webhook payloads carry CRM data, so ordinary members can neither see nor create subscriptions.

Events

EventFired when
lead.createdA new lead is created in CRM.
opportunity.stage_changedAn opportunity moves to a different pipeline stage.
form.submittedA CRM form submission is finalised.
submission.acceptedA payroll-family filing (FPS, EPS, NVR, CIS300, CIS verification, P11D / P11D(b)) was accepted by HMRC.
submission.rejectedHMRC rejected such a filing. An unknown outcome is not a rejection and fires nothing.
webhook.testOnly when you call POST /webhooks/subscriptions/test — never subscribable.

Submission events

submission.accepted and submission.rejected carry ids and statuses only (no figures, employee data or HMRC error text):

{
  "event": "submission.accepted",
  "data": {
    "filingId": "5b0c…",
    "filingType": "fps",
    "status": "accepted",
    "legalEntityId": "7c9e…",
    "payrollRunId": "…",
    "periodEnd": "2026-11-05",
    "correlationId": "…",
    "completedAt": "2026-11-12T10:00:00Z"
  },
  "sentAt": "2026-11-12T10:01:03.000Z"
}

Read the full filing with GET /payroll/filings/{filingId} (or the /cis / /p11d equivalent) under the matching read scope; see Payroll, CIS and P11D. They are detected by a sweep that runs about once a minute, so expect up to a minute or two of delay after HMRC's answer is recorded.

Managing subscriptions

# Create a subscription
curl -X POST https://api.ac-co.ai/webhooks/subscriptions \
  -H "Authorization: Bearer $ACCO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/webhooks/acco", "events": ["lead.created", "opportunity.stage_changed"]}'

The response includes a one-time secret (whsec_…) — store it now. It's never returned again; GET /webhooks/subscriptions only shows a display prefix.

{
  "id": "5f2c…",
  "url": "https://example.com/webhooks/acco",
  "events": ["lead.created", "opportunity.stage_changed"],
  "enabled": true,
  "secretPrefix": "whsec_ab12cd",
  "secret": "whsec_ab12cd34ef56…",
  "createdBy": "…",
  "createdAt": "2026-09-14T12:00:00.000Z",
  "updatedAt": "2026-09-14T12:00:00.000Z"
}

List, update (url / events / enabled), delete, and inspect recent deliveries for a subscription (GET /webhooks/subscriptions/:id/deliveries — status, HTTP response code, and last error, useful while debugging your receiver) round out the surface — see API Reference for exact shapes.

URL rules. The url must be https://, must not embed credentials, and must not point at a private, loopback or link-local address or an internal host name (localhost, *.local, *.internal, …). These are refused at create/update time with 400, and every delivery re-checks the resolved IP address before connecting. Redirects are not followed.

Rotating the secret. POST /webhooks/subscriptions/rotate-secret with {"id": "…"} returns a new one-time secret. The old secret stops signing immediately, including retries already queued — deploy the new secret to your receiver straight away.

Sending a test. POST /webhooks/subscriptions/test with {"id": "…"} queues a signed webhook.test delivery (data: {"test": true, …}) to an enabled subscription. It is sent within about a minute through the same signing and retry path as a real event; follow it in the deliveries list.

Delivery

Each event is POSTed to your url as JSON:

{
  "id": "6f1c0c1e-8a54-4b52-9d3e-2f0a7b9c1d11",
  "event": "lead.created",
  "data": { "lead_id": "…", "source": "…", "status": "new" },
  "sentAt": "2026-09-14T12:00:05.000Z"
}

with headers:

Content-Type: application/json
X-Acco-Event: lead.created
X-Acco-Delivery: 6f1c0c1e-8a54-4b52-9d3e-2f0a7b9c1d11
X-Acco-Signature: t=1757851200,v1=5257a869e7…

Retries. A non-2xx response (or a timeout — we wait 10s) is retried with exponential backoff (30s, 60s, 120s, … capped at 6h) up to 8 attempts total, after which the delivery is marked exhausted and dropped. Every attempt of the same delivery carries the same id (body) and X-Acco-Delivery (header), so make your endpoint idempotent on it — delivery is at-least-once, and a retry can arrive after your first attempt already succeeded but the response was lost in transit.

Auto-disable. An endpoint whose deliveries keep ending exhausted (5 in a row, with the first failure at least 24 hours old and no success in between) is disabled, with disabled_at and disabled_reason recorded. Nothing is deleted; set enabled: true through the update call to switch it back on, which resets the failure counters. Delivery records are kept for 30 days after they succeed or are exhausted.

Verifying signatures

X-Acco-Signature follows the same shape Stripe uses: t=<unix timestamp>,v1=<hex HMAC-SHA256>, computed over "${t}.${raw request body}" with your subscription's signing secret as the HMAC key. Always verify against the raw, unparsed request body — re-serializing parsed JSON can change byte-for-byte formatting and break the signature.

import { createHmac, timingSafeEqual } from "crypto";

function verifyAccoWebhook(
  secret: string,
  rawBody: string,
  signatureHeader: string,
  toleranceSeconds = 300,
): boolean {
  const parts = new Map(
    signatureHeader.split(",").map((kv) => kv.split("=", 2) as [string, string]),
  );
  const t = parts.get("t");
  const v1 = parts.get("v1");
  if (!t || !v1) return false;

  // Reject stale signatures — guards against a replayed request.
  if (Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;

  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`, "utf8").digest("hex");
  const expectedBuf = Buffer.from(expected, "hex");
  const gotBuf = Buffer.from(v1, "hex");
  return expectedBuf.length === gotBuf.length && timingSafeEqual(expectedBuf, gotBuf);
}

This is the exact algorithm used on our side (apps/services/public-api/lib/webhooks/signature.ts) — the two are unit-tested to stay in lockstep. If verification fails, double-check you're hashing the raw body your framework received, not a value re-stringified after JSON parsing.

Errors

insufficient_scope (403) for a missing webhooks:read / webhooks:write scope, 400 for a refused URL or a test sent to a disabled subscription, and the usual 401 / 404 cases (a caller who is not an org admin sees 404 / an empty list) — see Errors.

On this page