Marketing & email
Verify ActiveCampaign contact emails with an automation webhook
An ActiveCampaign automation webhook sends each contact to a Cloudflare Worker that verifies the email and writes the result to a custom field via API v3.
Updated 2026-11-26
This recipe verifies the email of each contact that enters an ActiveCampaign automation. A Webhook action posts the contact to a small Cloudflare Worker, the Worker verifies the address in the background and writes the result to an "Email status" custom field through ActiveCampaign's API v3, and the automation branches on that field with an If/Else. There is no native Qelka app for ActiveCampaign; the Worker is about seventy lines and runs on Cloudflare's free tier as far as we know, or on any host that runs JavaScript.
Why it matters: contacts arrive from forms, imports and integrations, and some of them are typos or long-dead mailboxes. Each one that bounces counts against your sender reputation with mailbox providers, which then filter more of your mail. Marking them before the first campaign keeps them out of it. See Email bounces explained.
What you need
- An ActiveCampaign account with automations and the Webhook action.
- Your account's API URL and API key, both shown in ActiveCampaign under Settings, Developer.
- A text custom contact field named Email status, and its ID (see the FAQ).
- A Cloudflare account and Wrangler, Cloudflare's CLI:
npm create cloudflare@latestsets up a Worker project. - A Qelka API key. A
sk_test_key returns simulated results and never spends credits: see Test mode. - A long random string to authenticate ActiveCampaign's calls, such as the output of
openssl rand -hex 32.
Steps
1. Write the Worker
const encoder = new TextEncoder()
const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))
function sameText(given, expected) {
if (!given || !expected) return false
const a = encoder.encode(given)
const b = encoder.encode(expected)
return a.byteLength === b.byteLength && crypto.subtle.timingSafeEqual(a, b)
}
function isAuthorized(request, env) {
const token = new URL(request.url).searchParams.get('token')
return sameText(request.headers.get('Authorization'), `Bearer ${env.WEBHOOK_SECRET}`) || sameText(token, env.WEBHOOK_SECRET)
}
async function readContact(request) {
const type = request.headers.get('Content-Type') ?? ''
if (type.includes('application/json')) {
const body = await request.json()
return { id: String(body.contact?.id ?? ''), email: String(body.contact?.email ?? '') }
}
const form = await request.formData()
return { id: String(form.get('contact[id]') ?? ''), email: String(form.get('contact[email]') ?? '') }
}
async function verifyEmail(email, env) {
for (let attempt = 1; attempt <= 3; attempt += 1) {
let response
try {
response = await fetch('https://api.qelka.com/v1/email', {
method: 'POST',
headers: {
Authorization: `Bearer ${env.QELKA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
signal: AbortSignal.timeout(15000),
})
} catch (error) {
console.warn(`email check skipped: ${error.name}`)
return 'unchecked'
}
if (response.ok) return (await response.json()).status
if ([429, 500, 502, 503].includes(response.status) && attempt < 3) {
const retryAfter = Number(response.headers.get('Retry-After'))
await sleep((retryAfter > 0 ? Math.min(retryAfter, 5) : attempt) * 1000)
continue
}
const failure = await response.json().catch(() => null)
console.warn(`email check skipped: ${failure?.error?.type ?? response.status} request ${response.headers.get('X-Request-Id')}`)
return 'unchecked'
}
}
async function storeStatus(contact, env) {
const status = await verifyEmail(contact.email, env)
const response = await fetch(`${env.AC_API_URL}/api/3/contacts/${contact.id}`, {
method: 'PUT',
headers: {
'Api-Token': env.AC_API_TOKEN,
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({ contact: { fieldValues: [{ field: env.AC_STATUS_FIELD_ID, value: status }] } }),
signal: AbortSignal.timeout(15000),
})
if (!response.ok) console.error(`ActiveCampaign answered ${response.status} for contact ${contact.id}: ${await response.text()}`)
}
export default {
async fetch(request, env, ctx) {
if (request.method !== 'POST') return new Response(null, { status: 405 })
if (!isAuthorized(request, env)) return new Response(null, { status: 401 })
let contact
try {
contact = await readContact(request)
} catch {
return new Response(null, { status: 400 })
}
if (!contact.id || !contact.email) return new Response(null, { status: 400 })
ctx.waitUntil(storeStatus(contact, env).catch((error) => console.error(`contact ${contact.id} not updated: ${error.message}`)))
return new Response(null, { status: 202 })
},
}
- The Worker reads both payload formats. New Webhook actions send JSON with a
contactobject holdingidandemail; older URL-only actions send form fields such ascontact[email]. ctx.waitUntillets the check and the API write finish after the202answer, so thefullcheck, which asks the recipient's mail server about the mailbox, never holds the automation.- The
PUTsets only the Email status field. ActiveCampaign leaves every field you do not send unchanged. - Any API problem writes
unchecked, so contacts keep moving and you can find them later. A failed ActiveCampaign write is logged with its status and body, visible withnpx wrangler tail.
2. Configure and deploy
Put the non-secret settings in wrangler.toml:
name = "activecampaign-email-check"
main = "src/index.js"
compatibility_date = "2026-11-01"
[vars]
AC_API_URL = "https://youraccount.api-us1.com"
AC_STATUS_FIELD_ID = "12"
Replace both values with yours. Store the three secrets with Wrangler, which prompts for each value, then deploy:
npx wrangler secret put QELKA_API_KEY
npx wrangler secret put AC_API_TOKEN
npx wrangler secret put WEBHOOK_SECRET
npx wrangler deploy
Wrangler prints the Worker's URL, on workers.dev unless you attach your own domain.
3. Add the Webhook action to the automation
- In ActiveCampaign, click Automations and Edit the automation you want, for example one that starts when a contact subscribes to your newsletter list. Pause it first if it is active.
- Click the plus sign at the top of the automation, then in Add an action click Workflow, then Webhook.
- Enter the Worker's URL and choose JSON as the output type.
- Under Authentication, enter
Authorizationas the name andBearerfollowed by a space and your random string as the value. ActiveCampaign hides the saved value when you reopen the action. - Under Include metadata, you can leave the default. The Worker only reads the contact's ID and email, which are always sent.
- Save, test with a test contact, then resume the automation.
If your Webhook action only shows a URL field, the newer options are not enabled for your account. Add ?token= and your random string to the URL instead: the Worker accepts it, but a secret in a URL can end up in logs, so switch to the Authentication field once you have it.
4. Wait, then branch on the field
After the webhook, add a Wait action of a few minutes, then an If/Else on the Email status field:
| Email status | Meaning | Suggested branch |
|---|---|---|
undeliverable |
Bad syntax, a domain that takes no mail, or a mailbox the server refused | Remove from lists or end the automation, and notify the owner |
risky |
A disposable inbox, a catch-all domain or a full mailbox | Tag for review and keep out of large sends |
deliverable |
The mail server accepted the mailbox | Continue |
unknown |
Not conclusive: greylisting, a timeout, a provider that does not answer mailbox checks | Continue. Never delete on this result; re-check later |
unchecked |
The API was not reached | Continue, and re-check |
To tell a disposable inbox from a catch-all domain, add a second field for the reason and send reason from the response in the same PUT. The email reference explains each reason.
5. Test the branches
Deploy with a sk_test_ key first. Run the automation for three test contacts, undeliverable@example.com, catchall@example.com and any other address: with a test key, the part before the @ picks the outcome, so each should land in a different branch.
Handle errors and rate limits
Nothing is billed on errors. 401 and 403 mean a wrong or restricted key, and 402 an empty balance: each writes unchecked, so a segment on that value is your alert, and a low-balance webhook warns you before the credits run out. 429 is retried after Retry-After. A key allows 200 requests per 10 seconds, so enroll an existing list in waves, and each check costs 1 credit. ActiveCampaign's API has its own limits, documented on its developer site. See Errors and Rate limits. For a large existing list, a bulk file check on an export is simpler than an automation.
Related
Frequently asked questions
Which ActiveCampaign plans include the Webhook action?
Why does the Worker answer before it checks the email?
How do I find the ID of my custom field?
More in Marketing & email
All integrationsPut this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.
- 100 free credits a month
- No card
- Test keys spend nothing
- Cancel any time