Connecting a CRM (Twenty) with the book.changed webhook

Being builtPartly works today — the limits are below.

finkpr can send a signed book.changed webhook when a book changes. It carries ids, not money: a small bridge checks the signature, reads what changed from the book's feed with its own read-only key, and keeps Twenty's companies, people and opportunities in step with the book's invoices.

What is live, and what is not yet

This recipe is early. Everything below ran end to end on 3 October 2026, against a finkpr control plane and book runtime running on our own test machine and a fresh Twenty v2.45.0. It has not run against a customer’s book.

The webhook is built and switched off on finkpr’s servers. It turns on per server, not per book. Until then the Connections page has no webhook section and you cannot add one. The feed fields the bridge reads (meta, tags, links) are already in every book’s feed.

How it works

your book changes
  └─ ~30 s later finkpr POSTs a signed book.changed to the bridge
       └─ the bridge checks the signature
            ├─ reads /feed/events since `after`    → which invoices changed
            ├─ reads /feed/postings                → each invoice's current state
            └─ upserts Company, Person, Opportunity in Twenty

The bridge is about 450 lines of JavaScript with no dependencies. It lives in the finkpr repository under integrations/twenty/. server.mjs runs it under Node 20 or later. src/handler.mjs exports the same handler as a Cloudflare Worker (export default { fetch }); we have only run the Node form.

The webhook finkpr sends

A few seconds after the book has been quiet for 30 seconds, finkpr POSTs:

{
  "id": "evt_01K…",
  "type": "book.changed",
  "created_at": "2026-10-03T17:44:12.000Z",
  "book_id": "bok_01K…",
  "head": "<commit sha the book is at now>",
  "after": "<commit sha you were last told about, or null>",
  "changes": 2,
  "events_url": "https://api.countbean.com/v1/books/bok_01K…/api/feed/events?after=<sha>"
}

There are no amounts, names or accounts in it. Several quick changes arrive as one webhook, and changes stops counting at 200.

Any 2xx answer counts as delivered. Anything else, including a redirect, is retried after 1 minute, 10 minutes, 1 hour and 12 hours, then every 12 hours. finkpr waits 10 seconds for an answer. After 10 failures in a row the webhook is switched off, the book’s chat gets a notice, and the Connections page offers Turn it back on. The next webhook then covers everything the CRM missed.

Removing the read key on the book page cuts the bridge off, whatever the webhook does.

Checking the signature

Each request carries X-Finkpr-Signature: t=<unix seconds>,v1=<hex>. v1 is HMAC-SHA256 with your secret over <t>.<the raw request body>, the same scheme Stripe uses. Turn away a t more than five minutes from your own clock.

import { createHmac, timingSafeEqual } from "node:crypto";

function verify(secret, header, rawBody, nowSeconds = Math.floor(Date.now() / 1000)) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
  const t = Number(parts.t);
  if (!t || Math.abs(nowSeconds - t) > 300) return false;
  const want = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
  const got = Buffer.from(parts.v1 ?? "", "hex");
  return got.length === want.length && timingSafeEqual(got, want);
}

The HMAC covers the bytes exactly as they arrived. Re-serialising parsed JSON will not reproduce them. The bridge’s own check (src/signature.mjs) is tested against the code finkpr signs with, so the two cannot drift apart.

Use the body only as a nudge. The bridge trusts two fields: book_id, which must match the book it serves, and after. It builds the feed address from its own setting and never fetches events_url. A body that pointed events_url elsewhere would otherwise collect your read key.

Step by step

1. Twenty: an API key

In Twenty, open Settings → MCP & APIs and create an API key. Name it finkpr-bridge. We used the Admin role and expiration Never. A role that can read and write Companies, People and Opportunities is enough. Copy the key; Twenty shows it once.

2. finkpr: a read key

On the book page, create an API key with read scope and name it twenty. Copy the cbk_… value. The bridge uses it for /feed/events and /feed/postings, and nothing else.

3. Run the bridge

The bridge needs a public https:// address: finkpr refuses http, private addresses and redirects. We ran it behind a Cloudflare tunnel.

cd integrations/twenty
export FINKPR_BOOK_ID=bok_01K…
export FINKPR_API_BASE=https://api.countbean.com
export FINKPR_READ_KEY=cbk_…
export TWENTY_BASE_URL=https://crm.example.com
export TWENTY_API_KEY=…
export FINKPR_WEBHOOK_SECRET=whsec_…   # from step 4
PORT=8787 node server.mjs
Setting What it is
FINKPR_WEBHOOK_SECRET the whsec_… secret finkpr shows once in step 4
FINKPR_BOOK_ID the one book this bridge serves; any other book_id gets 403
FINKPR_API_BASE the API origin on the book page, today https://api.countbean.com
FINKPR_READ_KEY the read-scope cbk_… key from step 2
TWENTY_BASE_URL, TWENTY_API_KEY your Twenty and the key from step 1
TWENTY_STAGE_OPEN, TWENTY_STAGE_PAID optional; default PROPOSAL and CUSTOMER
RECEIVABLE_PREFIXES optional, comma-separated; default Assets:Receivable, Assets:Receivables, Assets:AccountsReceivable

A missing setting answers 500 and reads nothing.

4. finkpr: the webhook

Go to Book → Connections → Webhook, enter the bridge’s address and choose Add webhook. Copy the signing secret into FINKPR_WEBHOOK_SECRET and restart the bridge. Then choose Send a test. The delivery list on the page should read Test: accepted (200).

5. Write invoices so the bridge can find them

One transaction per invoice, debiting a receivable account, with invoice: metadata. Payments credit the same account and carry the same invoice:.

2026-10-01 * "Lotus Studio" "September retainer"
  invoice: "INV-2026-031"
  due: 2026-10-31
  counterparty: "Lotus Studio"
  crm-contact: "Mei Tan"
  crm-contact-email: "mei@lotus-studio.example"
  Assets:Receivable:Lotus-Studio   4200 SGD
  Income:Consulting               -4200 SGD

2026-10-03 * "Lotus Studio" "Part payment"
  invoice: "INV-2026-031"
  Assets:Bank:Checking              2000 SGD
  Assets:Receivable:Lotus-Studio   -2000 SGD

In the chat, “Lotus paid 2000 on INV-2026-031” is enough for the agent to write the second one.

What lands in Twenty

In the book In Twenty
invoice: on a receivable posting an Opportunity named after the invoice number
sum of the invoice’s debits to receivables amount (exact, in amountMicros), in the posting’s currency
due: on the issuing transaction closeDate
debits minus credits still above zero stage = PROPOSAL (open)
debits minus credits at or below zero stage = CUSTOMER (paid)
counterparty:, else customer:, else the payee a Company with that name, linked to the opportunity
crm-contact: and crm-contact-email: a Person under that company, set as the point of contact

The first webhook (after: null) reconciles every invoice in the book. Later ones touch only the invoices named in the events since after. Each record is found by an exact name or email match and created if missing; an opportunity is patched only when a field differs. Running the same event twice changes nothing.

What we ran

On 3 October 2026, 13:49 to 13:52 Toronto time:

  1. A finkpr control plane with webhooks on, a book runtime, the bridge and a Cloudflare tunnel, all on one test machine, plus Twenty v2.45.0 on our own cluster. No production book or server was involved.
  2. The webhook was added through the Connections page; Send a test came back accepted (200).
  3. INV-2026-031 issued: Twenty showed it open, SGD 4,200, due 31 October, with Lotus Studio and Mei Tan attached, 36 seconds after the write.
  4. An expense with no invoice, an INV-2026-032 issued with only customer:, and a part payment on INV-2026-031, in one burst: one webhook, a new Harbour Coffee opportunity at USD 950.50, and INV-2026-031 left open.
  5. The final payment: INV-2026-031 moved to CUSTOMER, and Twenty still had one Lotus Studio after three deliveries.
  6. Reverting that payment: the feed reported the removal and INV-2026-031 went back to PROPOSAL.
  7. From the internet side, the bridge answered 401 to an unsigned request, a wrong secret and a ten-minute-old signature, and 403 to another book.

Each change reached Twenty about 36 seconds after the write: the 30-second quiet period plus the dispatcher’s tick. The scripts are in integrations/twenty/e2e/.

What it does not cover

  • The webhook is off on finkpr’s servers. Nothing here works on a live book until it is switched on.
  • A metadata-only edit sends nothing new to the bridge. Adding due: to an existing invoice does not change the transaction’s id, so /feed/events has no event for it, and the bridge only re-reads invoices that events name. The change reaches Twenty the next time that invoice is touched.
  • Removed invoices stay in Twenty. If every posting of an invoice is reverted, the bridge reports it as gone and leaves the opportunity alone.
  • An invoice in two currencies is skipped, not converted. So is a payment for an invoice the book never issued.
  • Records are matched by name. Rename an opportunity or company in Twenty and the bridge creates a new one next time.
  • One bridge serves one book.
  • A Twenty workflow alone is not enough. Twenty’s webhook trigger hands a workflow the parsed body, so the signature cannot be checked there. We did not build that path.
  • A slow Twenty can cause a retry. The bridge answers after it has written to Twenty. If that takes longer than finkpr’s 10 seconds, the event counts as failed and comes again; the upserts make the repeat harmless.
  • finkpr never messages your customers. A payment reminder is text for you to send yourself.

Something here wrong or missing? Put it on the board — it is public, and the reply is in the thread.