Integrations · Forms
Validate your Formbricks responses
Check the email answers of each Formbricks survey response. A small webhook receiver on your own server verifies each signed delivery from Formbricks, checks the addresses in the answers and tells your code the result: send it to Slack, your CRM or a review queue. By default only a definite invalid is flagged. If our API is slow or down, the response is simply reported as unchecked.
It is one TypeScript file with no dependencies, under the MIT licence (the text is at the top of the file). Download it: email-validation-formbricks.ts. It runs on any server with fetch and Web Crypto: Next.js, Hono, Express, Bun, Deno, Cloudflare Workers, Node 22 or later. Node 22.18 and later run a .ts file as it is; older Node through a TypeScript build step or npx tsx.
How it works, and its limits
Formbricks sends its webhook after it has stored the response, so nothing can refuse a response. The receiver checks right after, and changes nothing in Formbricks:
- Formbricks sends a delivery on Response Finished (
responseFinished, the default; theeventsoption addsresponseCreatedorresponseUpdated). The receiver verifies its signature first: Formbricks signs each delivery in the Standard Webhooks format (webhook-id,webhook-timestamp,webhook-signature) with the webhook's signing secret. A delivery without the right signature, or older than 5 minutes, is answered401and nothing is read. - It answers Formbricks
200at once, so Formbricks' 5-second limit never runs out. - It finds the addresses in the answers: an answer that is exactly one address (a question with the input type Email, a hidden field) or a Contact Info answer holding one. Text that only mentions an address, a link and a
mailto:are not checked. Withfields, only the answers you name are read. At most 5 addresses a response. - It checks each address with one call to our API and calls your
onResultfunction once with the verdicts:{ event, responseId, surveyId, messageId, flagged, checks }, where each check has the question (field), anoutcome(flagged,allowedorunchecked) and our answer. It never holds the address.
What you do with a flagged response is yours: tell yourself, mark the person in your CRM, or delete the response with Formbricks' own API. Each answer is remembered under the address's SHA-256, so the same person answering a second survey is answered from memory without a new check. Only definite answers are remembered: a timeout or an unknown is checked again next time.
What you need
- An API key from the API keys page with the permission Validate addresses, and a daily credit cap. Put it in your server's environment as
EV_API_KEY. - A Formbricks webhook and its signing secret (
whsec_…), which Formbricks makes for each new webhook. Put it in your server's environment asFORMBRICKS_WEBHOOK_SECRET.
Webhooks and the API are part of Formbricks' free Community Edition, which you can host yourself (Formbricks' pricing page).
Set it up
Copy
email-validation-formbricks.tsinto your server code, for example tolib/.Run the receiver. On Cloudflare Workers:
import { createFormbricksWebhook } from './email-validation-formbricks.ts'; // Once per isolate, so the receiver's memory (one check per address) lasts across requests. let receive: ReturnType<typeof createFormbricksWebhook> | undefined; export default { fetch(request: Request, env: Record<string, string>, ctx: ExecutionContext) { receive ??= createFormbricksWebhook({ apiKey: env.EV_API_KEY, webhookSecret: env.FORMBRICKS_WEBHOOK_SECRET, onResult: async (result) => { if (result.flagged) await notifyTeam(result); // your code: Slack, email, CRM }, }); return receive(request, ctx); // ctx.waitUntil keeps the checks running after the 200 }, };In the Next.js App Router:
export const POST = createFormbricksWebhook({ ..., waitUntil: after }), withafterfromnext/server. In Express, createcreateFormbricksWebhookHandler(options)once and call it with the raw body (the signature covers the exact bytes):import express from 'express'; import { createFormbricksWebhookHandler } from './email-validation-formbricks.ts'; const handle = createFormbricksWebhookHandler({ /* the same options */ }); app.post('/webhooks/formbricks', express.raw({ type: '*/*', limit: '1mb' }), async (req, res) => { const result = await handle({ body: req.body, headers: req.headers }); res.status(result.status).json(result.body); });In Formbricks: Configuration → Integrations → Manage Webhooks → Add Webhook. Enter your receiver's address and press Test Endpoint. Choose the trigger Response Finished and the surveys to check (all, or some), and save. Until the secret is set, the receiver answers every delivery
401; Formbricks still lets you save the webhook.Formbricks shows the webhook's signing secret right after you create it (and later in the webhook's settings). Copy it into
FORMBRICKS_WEBHOOK_SECRETon your server and restart or redeploy the receiver.Test it. In the webhook's settings press Test Endpoint again and look at your server's answer: a working receiver answers
200with"ignored": "test"and checks nothing. A401means the secret is wrong or missing. Then answer a survey with an address of yours that receives mail and watchonResult(outcome: 'allowed'). To see a flagged answer, callcreateEmailCheck(options)from your server withno_mailbox@sandbox.email-validation.org: it is free and always answersinvalid. Never answer a survey with a test or sandbox address: a follow-up email from the survey or from your own tools would bounce and hurt your sender.
Options
| Option | Default | What it does |
|---|---|---|
apiKey | required | Our API key. Missing: nothing is checked. |
webhookSecret | required | The webhook's signing secret, whsec_…. Until it is set, every delivery is answered 401. |
region | us | eu validates addresses in the EU and stores their results there, with the same key |
flag | ['invalid'] | Statuses that flag an address, from invalid, disposable, catch_all, unknown |
events | ['responseFinished'] | The triggers that start a check: responseCreated, responseUpdated, responseFinished |
fields | every answer | Only these answers are read: question ids, question codes or hidden field names |
timeoutMs | 6000 | How long to wait for our answer before the address is unchecked (whole milliseconds, at most 60000) |
toleranceS | 300 | How far a delivery's signed time may be from now, in seconds (at most 3600) |
store | none | { get(key), set(key, value) } (Workers KV, Redis, a table) to remember answers across restarts and instances |
onResult | none | Called once per accepted delivery, after its checks, with the verdicts, never an address |
waitUntil | none | Keeps the checks running after the answer on serverless hosts (Next.js after); Workers pass ctx instead |
When something fails
If our API is slow, out of reach or out of credits, the address is reported unchecked with the reason in decision.error; Formbricks has already had its 200. A delivery without a valid, fresh signature is answered 401 and nothing is checked. Formbricks tries a delivery again only after a network error, a timeout, a redirect, a 408, a 429 or a 5xx, not after a 401: so if the secret is wrong, those responses stay unchecked until you fix it. A webhook made before Formbricks signed its deliveries has no secret and is always answered 401: add a new one. Bodies over 1 MiB are refused (413).
What it costs
Each checked address uses one credit. unknown results, malformed addresses and test addresses are free. A remembered address is answered without a new check; to share answers across several instances, pass a store.
Privacy
The file writes no log line and puts no key, secret or address in an error or an answer. onResult gets the event, the response and survey ids, the question and our answer, never the address. The address goes only in the body of a request to our API, never in a URL.