Skip to content

Marketing & email

Verify Klaviyo profile emails with a flow webhook

A Klaviyo flow webhook sends each new profile to a small handler that verifies the email and writes email_status back to the profile through Klaviyo's API.

Updated 2026-11-26

This recipe adds an email check to a Klaviyo flow. A Webhook action posts each profile that enters the flow to a small handler you host. The handler reads the profile's email from Klaviyo's API, verifies it, and writes email_status, email_reason and email_checked_at back to the profile as custom properties. Your segments and conditional splits then use those properties. There is no native Qelka app for Klaviyo, and a flow webhook cannot write to Klaviyo by itself: the handler does the write through Klaviyo's Profiles API.

Why it matters: Klaviyo sends to the profiles you give it. Profiles that come from forms, imports or integrations include typos and dead mailboxes, and each one that bounces counts against your sender reputation with mailbox providers. Tagging them before your first campaign keeps them out of it. See Email bounces explained.

What you need

  • A Klaviyo account where you can add a Webhook action to a flow. Klaviyo requires two-step authentication on your login and a Manager, Admin or Owner role for that.
  • A Klaviyo private API key with read and write access to profiles (scopes profiles:read and profiles:write).
  • A place to host a Node.js 18+ service on HTTPS. Klaviyo requires the URL to start with https://, have a valid, non self-signed certificate and not redirect.
  • A Qelka API key. A sk_test_ key returns simulated results and never spends credits: see Test mode.
  • A long random string to authenticate Klaviyo's calls, such as the output of openssl rand -hex 32.

Steps

1. Write the handler

The handler answers Klaviyo at once with 202, then does the work, so a slow mail server never makes Klaviyo wait or retry. It needs express: npm install express.

javascript
import { timingSafeEqual } from 'node:crypto'
import express from 'express'

const klaviyoHeaders = {
  Authorization: `Klaviyo-API-Key ${process.env.KLAVIYO_PRIVATE_KEY}`,
  revision: '2026-10-15',
  accept: 'application/vnd.api+json',
  'content-type': 'application/vnd.api+json',
}

const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))

function hasSecret(received) {
  const expected = Buffer.from(process.env.WEBHOOK_SECRET ?? '')
  const given = Buffer.from(received ?? '')
  return expected.length > 0 && given.length === expected.length && timingSafeEqual(given, expected)
}

async function klaviyo(method, path, body) {
  const response = await fetch(`https://a.klaviyo.com/api${path}`, {
    method,
    headers: klaviyoHeaders,
    body: body === undefined ? undefined : JSON.stringify(body),
    signal: AbortSignal.timeout(15000),
  })
  if (!response.ok) throw new Error(`Klaviyo ${method} ${path} answered ${response.status}: ${await response.text()}`)
  return response.status === 204 ? null : response.json()
}

async function verifyEmail(email) {
  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 ${process.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 { status: 'unchecked', reason: '' }
    }
    if (response.ok) return response.json()
    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, 10) : attempt * 2) * 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 { status: 'unchecked', reason: '' }
  }
}

async function checkProfile(profileId) {
  const profile = await klaviyo('GET', `/profiles/${profileId}?fields[profile]=email`)
  const email = profile.data.attributes.email
  if (!email) return

  const result = await verifyEmail(email)
  await klaviyo('PATCH', `/profiles/${profileId}`, {
    data: {
      type: 'profile',
      id: profileId,
      attributes: {
        properties: {
          email_status: result.status,
          email_reason: result.reason ?? '',
          email_checked_at: new Date().toISOString(),
        },
      },
    },
  })
}

const app = express()
app.use(express.json())

app.post('/klaviyo/verify-email', (request, response) => {
  if (!hasSecret(request.get('X-Webhook-Secret'))) return response.sendStatus(401)
  const profileId = request.body?.profile_id
  if (typeof profileId !== 'string' || profileId.length === 0) return response.sendStatus(400)

  response.sendStatus(202)
  checkProfile(profileId).catch((error) => console.error(`profile ${profileId} not updated: ${error.message}`))
})

app.listen(Number(process.env.PORT ?? 3000))

Set KLAVIYO_PRIVATE_KEY, WEBHOOK_SECRET and QELKA_API_KEY in your host's secret settings, never in the code. Because the handler answers before it works, it can run the full check, which asks the recipient's mail server about the mailbox and can take several seconds. Any API failure writes email_status: unchecked, so the profile keeps flowing and you can find it later. A Klaviyo failure is logged with its status and body.

2. Add the Webhook action to a flow

  1. Create or open a flow, for example one triggered when someone is added to your newsletter list.
  2. Drag the Webhook action from the left sidebar of the flow builder to the top of the flow.
  3. Set the destination URL to your handler, such as https://hooks.yourdomain.example/klaviyo/verify-email.
  4. With Add Headers, add the header X-Webhook-Secret with your random string as its value. Klaviyo partially hashes header values once saved, so keep a copy in your secret store.
  5. In the body, which must be JSON, send the profile ID:
json
{ "profile_id": "{{ person.KlaviyoID }}" }

person.KlaviyoID is the profile's Klaviyo ID in Klaviyo's personalization tags. In the webhook editor, Klaviyo's View profile properties panel lists the variables you can copy. Klaviyo sends only POST requests, and adds an X-Klaviyo-Flow-ID header naming the flow, which you can log.

3. Wait, then split on the result

Klaviyo counts any 2xx answer as a successful request, and the handler answers before it writes the property, so the property lands a moment after the webhook step. Add a Time delay after the webhook, a few minutes is plenty, then a Conditional split on the profile property email_status:

email_status Meaning Suggested branch
undeliverable Bad syntax, a domain that takes no mail, or a mailbox the server refused Exit the flow and keep the profile out of campaigns with a segment that excludes it
risky A disposable inbox, a catch-all domain or a full mailbox Branch on email_reason: drop disposable from marketing, send catch_all with care, re-check mailbox_full later
deliverable The mail server accepted the mailbox Continue
unknown Not conclusive: greylisting, a timeout, a provider that does not answer mailbox checks Continue. Never suppress on this result; re-check later
unchecked The API was not reached Continue, and re-check

Then build a segment of profiles whose email_status is undeliverable and exclude it from every campaign. The email reference explains each reason.

4. Test it

Point the webhook at your handler with a sk_test_ key, then add three test profiles to the trigger list: undeliverable@example.com, catchall@example.com and any other address. With a test key the part before the @ picks the result, so each profile should end on a different branch. Klaviyo's Webhook Analytics page shows failed requests: retryable errors are retried with exponential backoff, and others go to a Skipped queue.

Handle errors and rate limits

Nothing is billed on errors. 401 and 403 mean a wrong or restricted key, 402 an empty balance; each writes unchecked, so a segment on email_status = unchecked is your alert. 429 is retried after Retry-After. A key allows 200 requests per 10 seconds, which matters when you enroll a large list at once, and each check costs 1 credit. Klaviyo's Profiles endpoints have their own rate limits, listed in its API reference. See Errors and Rate limits. For an existing list, a bulk file check on an export is cheaper in requests than a flow.

Frequently asked questions

Can I use webhooks in my Klaviyo flows?
Klaviyo's documentation requires two-step authentication on your login and a Manager, Admin or Owner role to add or edit a webhook action. It does not list a plan requirement on that page, but plans change: as far as we know, check yours before building.
Why does the webhook send the profile ID instead of the email?
The handler needs the profile ID anyway to write the result back, and reading the email from Klaviyo's API at run time means it checks the address the profile has now. It also keeps the webhook body to one variable, which is easy to get right in the editor.
Which revision header should I send to Klaviyo's API?
Klaviyo versions its API by date in the revision header. The code uses 2026-10-15, the revision shown in Klaviyo's reference when this guide was written. Pin one revision, and move to a newer one deliberately after reading Klaviyo's changelog.

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