Skip to content

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@latest sets 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

javascript
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 contact object holding id and email; older URL-only actions send form fields such as contact[email].
  • ctx.waitUntil lets the check and the API write finish after the 202 answer, so the full check, which asks the recipient's mail server about the mailbox, never holds the automation.
  • The PUT sets 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 with npx wrangler tail.

2. Configure and deploy

Put the non-secret settings in wrangler.toml:

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:

bash
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

  1. 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.
  2. Click the plus sign at the top of the automation, then in Add an action click Workflow, then Webhook.
  3. Enter the Worker's URL and choose JSON as the output type.
  4. Under Authentication, enter Authorization as the name and Bearer followed by a space and your random string as the value. ActiveCampaign hides the saved value when you reopen the action.
  5. Under Include metadata, you can leave the default. The Worker only reads the contact's ID and email, which are always sent.
  6. 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.

Frequently asked questions

Which ActiveCampaign plans include the Webhook action?
ActiveCampaign's help article on the automation Webhook action lists Starter, Plus, Pro and Enterprise at the time of writing. Plans change, so as far as we know it is available, but check yours. If your action only shows a URL field, the newer options such as JSON and authentication are not enabled for your account yet, and the handler below still works with form data.
Why does the Worker answer before it checks the email?
A full check asks the recipient's mail server about the mailbox and can take several seconds. Answering 202 at once means the automation never waits on that, and the result is written to the contact through the API a moment later. That is why the automation has a Wait step before it reads the field.
How do I find the ID of my custom field?
Call GET /api/3/fields on your account's API URL with your Api-Token header. The response lists every custom contact field with its id, title and personalization tag. Put the id of the Email status field in the Worker's AC_STATUS_FIELD_ID variable.

More in Marketing & email

All integrations

Put 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