Skip to content

CRM

Validate phone numbers and emails in Pipedrive

Check the email and phone of each new Pipedrive person with a webhook and a small handler, then write the result to custom person fields through the API.

Updated 2026-11-26

This recipe checks the email and phone number of every person created in Pipedrive and writes the answer to two custom person fields, so you can filter bad contacts out of campaigns and fix typos before a sales rep picks up the phone. There is no native Qelka app for Pipedrive: a Pipedrive webhook calls a small handler of yours, the handler calls the API and writes the result back through Pipedrive's REST API.

What you need

  • A Pipedrive company where you can create custom person fields and webhooks, and a Pipedrive API token. Pipedrive shows each user's token in their personal preferences, under API. Pipedrive says regular webhooks are available on all plans, as far as we know: check yours.
  • A Qelka API key. A sk_test_ key returns simulated results and never spends credits: see Test mode. A restricted key limited to email and phone is enough for this handler.
  • A place to run about a hundred lines of JavaScript that receives a web Request: Cloudflare Workers or Vercel below, or any server through a framework such as Hono.

Steps

1. Create two custom person fields

In Pipedrive's data fields settings, add two person fields of the text type: Email status and Phone check. Each custom field has a 40-character key. Read the keys with the API, and keep the two values for step 3:

bash
curl "https://yourcompany.pipedrive.com/api/v2/personFields" \
  -H "x-api-token: $PIPEDRIVE_API_TOKEN"

The key of each field is its field_code.

2. The handler

Save as pipedrive-webhook.js:

javascript
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

function safeEqual(a, b) {
  if (a.length !== b.length) return false
  let difference = 0
  for (let index = 0; index < a.length; index += 1) difference |= a.charCodeAt(index) ^ b.charCodeAt(index)
  return difference === 0
}

async function check(env, path, body, timeoutMs) {
  for (let attempt = 1; attempt <= 2; attempt += 1) {
    let response
    try {
      response = await fetch(`https://api.qelka.com/v1${path}`, {
        method: 'POST',
        headers: { Authorization: `Bearer ${env.QELKA_API_KEY}`, 'Content-Type': 'application/json' },
        body: JSON.stringify(body),
        signal: AbortSignal.timeout(timeoutMs),
      })
    } catch (error) {
      console.warn(`check skipped: ${path} unreachable (${error.name})`)
      return null
    }
    if (response.ok) return response.json()
    if (attempt === 1 && [429, 500, 502, 503].includes(response.status)) {
      const retryAfter = Number(response.headers.get('Retry-After'))
      await sleep((retryAfter > 0 ? Math.min(retryAfter, 5) : 1) * 1000)
      continue
    }
    const failure = await response.json().catch(() => ({}))
    console.warn(`check skipped: ${failure.error?.type ?? response.status} request ${response.headers.get('X-Request-Id')}`)
    return null
  }
  return null
}

const pipedrive = (env, path, init = {}) =>
  fetch(`https://${env.PIPEDRIVE_DOMAIN}.pipedrive.com/api/v2${path}`, {
    ...init,
    headers: { 'x-api-token': env.PIPEDRIVE_API_TOKEN, 'Content-Type': 'application/json' },
    signal: AbortSignal.timeout(8000),
  })

const primaryValue = (items) => (items ?? []).find((item) => item.primary)?.value ?? items?.[0]?.value

async function checkPerson(env, id) {
  const fields = `${env.EMAIL_STATUS_FIELD},${env.PHONE_CHECK_FIELD}`
  const found = await pipedrive(env, `/persons/${id}?custom_fields=${fields}`)
  if (!found.ok) return console.warn(`person ${id} not readable: ${found.status}`)
  const person = (await found.json()).data
  if (person.custom_fields?.[env.EMAIL_STATUS_FIELD] || person.custom_fields?.[env.PHONE_CHECK_FIELD]) return

  const email = primaryValue(person.emails)
  const phone = primaryValue(person.phones)
  const [emailResult, phoneResult] = await Promise.all([
    email ? check(env, '/email', { email, mode: 'full' }, 15000) : null,
    phone ? check(env, '/phone', { phone, country: env.DEFAULT_COUNTRY || undefined }, 8000) : null,
  ])

  const customFields = {}
  if (email) customFields[env.EMAIL_STATUS_FIELD] = emailResult ? emailResult.status : 'unchecked'
  if (phone) customFields[env.PHONE_CHECK_FIELD] = !phoneResult ? 'unchecked' : phoneResult.status === 'valid' ? phoneResult.e164 : phoneResult.status
  if (Object.keys(customFields).length === 0) return

  const saved = await pipedrive(env, `/persons/${id}`, { method: 'PATCH', body: JSON.stringify({ custom_fields: customFields }) })
  if (!saved.ok) console.warn(`person ${id} not updated: ${saved.status}`)
}

export async function handle(request, env, waitUntil) {
  if (request.method !== 'POST') return new Response(null, { status: 405 })
  const expected = `Basic ${btoa(`${env.WEBHOOK_USER}:${env.WEBHOOK_PASSWORD}`)}`
  if (!safeEqual(request.headers.get('Authorization') ?? '', expected)) return new Response(null, { status: 401 })

  const payload = await request.json().catch(() => null)
  if (payload?.meta?.entity !== 'person' || payload.meta.action !== 'create') return new Response(null, { status: 204 })

  waitUntil(checkPerson(env, payload.meta.entity_id).catch((error) => console.error(`person check failed: ${error.name}`)))
  return new Response(null, { status: 204 })
}

The handler answers Pipedrive at once and does the work in the background. Pipedrive treats a delivery as failed when it gets no 2xx answer within its timeout (10 seconds in its current docs), retries it, and deletes webhooks that keep failing, so a slow mail server must never hold the answer.

mode: 'full' runs the mailbox check, the only way to get deliverable, and the 15-second timeout covers a slow mail server. If your host stops background work sooner, switch to mode: 'fast': it catches typos, dead domains and disposable inboxes, and answers unknown with smtp_not_checked when those pass. See the email reference.

A number written without + needs a country to be read. Set DEFAULT_COUNTRY to the two-letter code of most of your contacts, or leave it empty: those numbers then come back unknown. See the phone reference.

3. Deploy it with its secrets

Expose handle with a two-line entry file for your host:

import { handle } from './pipedrive-webhook.js'

export default {
  fetch: (request, env, ctx) => handle(request, env, (task) => ctx.waitUntil(task)),
}
import { waitUntil } from '@vercel/functions'
import { handle } from '../pipedrive-webhook.js'

export default {
  fetch: (request) => handle(request, process.env, waitUntil),
}

On Vercel the entry file is api/pipedrive.js, and package.json needs "type": "module". Store each value as a secret, never in the code: wrangler secret put QELKA_API_KEY on Cloudflare, vercel env add QELKA_API_KEY on Vercel, and the same for PIPEDRIVE_API_TOKEN, PIPEDRIVE_DOMAIN (the yourcompany part of your Pipedrive address), EMAIL_STATUS_FIELD, PHONE_CHECK_FIELD, WEBHOOK_USER, WEBHOOK_PASSWORD (a long random string) and, optionally, DEFAULT_COUNTRY.

4. Create the webhook

Open Pipedrive's webhooks page (in the Tools and integrations menu, named Tools and apps in some accounts) and create a webhook:

  • Event action: create. Event object: person.
  • Endpoint URL: the URL of your deployed handler.
  • HTTP Auth username and password: the values of WEBHOOK_USER and WEBHOOK_PASSWORD.

Pipedrive creates webhooks in version 2 by default. Its payload carries meta.action, meta.entity and meta.entity_id, which is all the handler reads: it fetches the person itself, so it always works on current data.

5. Test it

With a sk_test_ key, create a person with the email disposable@example.com. Within seconds, Email status reads risky. undeliverable@example.com gives undeliverable, any other well-formed address deliverable, and phone numbers are parsed for real. Then swap in a live key.

6. Use the result

Build filters and list views on the two fields:

Email status Meaning Suggested action
undeliverable Bad syntax, no domain, or the mailbox was refused Exclude from campaigns and ask the owner to get a correct address
risky Disposable inbox, catch-all domain or full mailbox Review before sending sequences
deliverable The mail server accepted the mailbox Nothing to do
unknown or unchecked Not conclusive, or the API was unreachable Keep the person, check again later

An unknown email is not a bad email, so never delete a person on it. Phone check holds the number in E.164 when it is valid, ready for your dialer, or invalid, unknown or unchecked. Format phone numbers in E.164 explains why storing E.164 pays off.

Handle errors and rate limits

Every failure ends as unchecked and never blocks Pipedrive: the person is saved, the handler logs the error type and the X-Request-Id, and you can filter on unchecked later. No error is billed. 401 and 403 mean a wrong or restricted key, 402 an empty balance: alert on them rather than retry. A 429 is retried once after Retry-After. A key allows 200 requests per 10 seconds, which a manual import of thousands of persons can exceed: for those, use a bulk file check. Each email check costs 1 credit and each basic phone check 1. See Errors and Rate limits.

On Pipedrive's side, a failed read or update is logged with its HTTP status. Pipedrive also limits its own API, so keep the handler to one read and one write per person, as above.

Frequently asked questions

Do I need a paid Pipedrive plan?
Pipedrive's support pages say regular webhooks are available on all plans, while webhooks sent from Automations need Advanced or higher. This recipe uses a regular webhook, but plans change: check yours before you build. Custom person fields and API tokens are also needed.
Will updating the person trigger the webhook again?
No. The webhook listens to created persons only, and writing the custom fields is a change event. The handler also reads the person before checking it and stops when a status is already stored, so a redelivered or duplicated event costs nothing.
Can I check people who are already in Pipedrive?
Yes. Export the persons, run a bulk file check, and import the statuses back into the same custom fields. Calling the handler for thousands of persons at once would hit the rate limits of both APIs, so the file route is simpler and cheaper to monitor.

More in CRM

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