Skip to content

E-commerce & payments

Validate phone numbers and emails in BigCommerce

Check the email and phone of new BigCommerce customers and orders from webhooks, then save the verdict to a customer attribute or the order's staff notes.

Updated 2026-11-26

This recipe checks the email and phone number of each new BigCommerce customer and order. Two webhooks, store/customer/created and store/order/created, call a small receiver. Because BigCommerce only sends ids, the receiver fetches the record, calls the API, and writes the verdict back: to a customer attribute for customers, to the staff notes for orders, together with an IP check on the order. BigCommerce has no native Qelka app, so the receiver sits in between.

What you need

  • A BigCommerce store and a store-level API account, created in the control panel under Settings, Store-level API accounts. Give it the Customers scope with modify access, to read customers and write attribute values, and the Orders scope with modify access, to read orders and write staff notes. Webhooks need no extra scope.
  • A Qelka API key in QELKA_API_KEY. A sk_test_ key returns simulated results and never spends credits: see Test mode.
  • A Node.js 18 or later server reachable over HTTPS on port 443, with npm install express @qelka/sdk and these variables: BC_STORE_HASH, BC_ACCESS_TOKEN, BC_WEBHOOK_SECRET (a long random string you choose) and BC_ATTRIBUTE_ID (step 1).

Steps

1. Create the customer attribute

Customer attributes are created once, then filled per customer. Create a text attribute to hold the verdict:

bash
curl -X POST "https://api.bigcommerce.com/stores/$BC_STORE_HASH/v3/customers/attributes" \
  -H "X-Auth-Token: $BC_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '[{"name": "Contact validation", "type": "string"}]'

Put the id from the response in BC_ATTRIBUTE_ID. BigCommerce limits how many customer attributes a store can have, so reuse this one rather than creating one per field.

2. The receiver

javascript
import crypto from 'node:crypto'
import express from 'express'
import { ApiConnectionError, ApiError, Client } from '@qelka/sdk'

const storeApi = `https://api.bigcommerce.com/stores/${process.env.BC_STORE_HASH}`
const validation = new Client({ apiKey: process.env.QELKA_API_KEY, timeoutMs: 8000 })
const app = express()

function secretMatches(header) {
  const received = Buffer.from(header ?? '')
  const wanted = Buffer.from(process.env.BC_WEBHOOK_SECRET)
  return received.length === wanted.length && crypto.timingSafeEqual(received, wanted)
}

async function bigcommerce(path, init = {}) {
  const response = await fetch(`${storeApi}${path}`, {
    ...init,
    headers: { 'X-Auth-Token': process.env.BC_ACCESS_TOKEN, 'Content-Type': 'application/json', Accept: 'application/json' },
    signal: AbortSignal.timeout(10000),
  })
  if (!response.ok) throw new Error(`BigCommerce ${init.method ?? 'GET'} ${path} answered ${response.status}`)
  return response.json()
}

async function settle(task) {
  try {
    return await task()
  } catch (error) {
    if (!(error instanceof ApiError) && !(error instanceof ApiConnectionError)) throw error
    if (error instanceof ApiError && error.type === 'unprocessable_input') return null
    console.error('validation skipped', error instanceof ApiError ? `${error.type} ${error.requestId}` : 'unreachable')
    return null
  }
}

async function verdictFor(email, phone, country) {
  const [emailResult, phoneResult] = await Promise.all([
    email ? settle(() => validation.email.verify({ email })) : null,
    phone ? settle(() => validation.phone.validate({ phone, country: country || undefined })) : null,
  ])
  const emailPart = email ? `email ${emailResult ? emailResult.status : 'unchecked'}` : 'no email'
  const suggestion = emailResult?.did_you_mean ? ` (did you mean ${emailResult.did_you_mean}?)` : ''
  const phonePart = phone ? `phone ${phoneResult ? phoneResult.status : 'unchecked'}` : 'no phone'
  return `${emailPart}${suggestion}, ${phonePart}`
}

async function onCustomerCreated(id) {
  const { data } = await bigcommerce(`/v3/customers?id:in=${id}&include=addresses`)
  const customer = data[0]
  if (!customer) return

  const verdict = await verdictFor(customer.email, customer.phone, customer.addresses?.[0]?.country_code)
  await bigcommerce('/v3/customers/attribute-values', {
    method: 'PUT',
    body: JSON.stringify([{ attribute_id: Number(process.env.BC_ATTRIBUTE_ID), customer_id: id, value: verdict }]),
  })
}

async function onOrderCreated(id) {
  const order = await bigcommerce(`/v2/orders/${id}`)
  const billing = order.billing_address ?? {}
  const ip = order.ip_address || order.ip_address_v6

  const [verdict, lookup] = await Promise.all([
    verdictFor(billing.email, billing.phone, billing.country_iso2),
    ip ? settle(() => validation.ip.lookup({ ip })) : null,
  ])
  const flags = lookup ? Object.keys(lookup.flags).filter((flag) => lookup.flags[flag]) : []
  const ipPart = lookup ? `, IP risk ${lookup.risk.level}${flags.length ? ` (${flags.join(', ')})` : ''}` : ''
  const note = `Validation: ${verdict}${ipPart}`

  await bigcommerce(`/v2/orders/${id}`, {
    method: 'PUT',
    body: JSON.stringify({ staff_notes: [order.staff_notes, note].filter(Boolean).join('\n') }),
  })
}

app.post('/bigcommerce/webhooks', express.json(), (req, res) => {
  if (!secretMatches(req.get('X-Webhook-Secret'))) return res.sendStatus(401)
  res.sendStatus(200)

  const { scope, data } = req.body
  const task = scope === 'store/customer/created' ? onCustomerCreated : scope === 'store/order/created' ? onOrderCreated : null
  if (task && data?.id) task(data.id).catch((error) => console.error('webhook task failed', scope, data.id, error.message))
})

app.listen(3000)

The route answers 200 before any API call. BigCommerce treats a missing or non-200 answer as a failure and retries with growing delays, and it deactivates a webhook that keeps failing, so never make it wait for the checks. The staff note is appended to what is already there, because a PUT on the order replaces staff_notes with the value you send.

Guest orders have no customer record (their customer_id is 0), which is why orders are checked from the billing address rather than through the customer.

3. Create the webhooks

BigCommerce webhooks are created through the API. Create one per scope, with the same destination and your secret in a custom header:

bash
curl -X POST "https://api.bigcommerce.com/stores/$BC_STORE_HASH/v3/hooks" \
  -H "X-Auth-Token: $BC_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"scope": "store/customer/created", "destination": "https://example.com/bigcommerce/webhooks", "is_active": true, "headers": {"X-Webhook-Secret": "the value of BC_WEBHOOK_SECRET"}}'

Run it again with "scope": "store/order/created". The callback body carries the scope and data with the record's type and id, nothing more. Create a test customer and a test order, then check the attribute and the staff notes.

4. Read the verdict

Verdict Meaning Suggested action
email undeliverable Bad syntax, dead domain or refused mailbox Contact the customer by phone, keep the address out of campaigns
email risky Disposable inbox, catch-all domain or full mailbox Review before shipping high-value orders
email deliverable or unknown Accepted, or not conclusive Nothing to do
phone invalid Not a number in its country's plan Ask for a correct number before a courier needs it
phone unknown No + and no country to read it with Usually a number typed without its country code
IP risk high or tor Tor exit, known VPN or proxy network Hold the order for review before fulfilment
unchecked The API was unreachable or refused the key Re-check later

A VPN alone is a weak signal: many honest buyers use one. Combine it with the email and the order value before you cancel anything. See the email reference, the phone reference and Flag VPN and data center traffic.

Handle errors and rate limits

Nothing is billed on errors. The SDK retries 429, 502 and 503, waiting Retry-After. 401 invalid_api_key, 403 forbidden and 402 insufficient_credits end as unchecked in the verdict and in your logs with the request id: alert on them. A key allows 200 requests per 10 seconds. BigCommerce can deliver an event more than once; each callback carries a hash you can store to skip repeats, since a repeat check spends credits again. Each email check costs 1 credit, each basic phone check 1 and each IP lookup 1. For the customers you already have, export them and run a bulk file check. See Errors and Rate limits.

Frequently asked questions

Why does the receiver fetch the customer or order again?
BigCommerce webhooks are light by design: the callback only says which event happened and the id of the record, never the email or the phone. The receiver reads the record through the REST API with your access token, which also means a forged callback can only make it look at your own data.
How do I know a callback really comes from BigCommerce?
BigCommerce does not sign callbacks. When you create the webhook you can pass custom headers, which it sends with every callback, so set a long random secret in one header and reject requests that do not carry it. The destination must be HTTPS on port 443.
Can this stop the order or the signup?
No. The webhooks fire after the customer or the order exists, so the receiver labels the record and your team acts on it: hold the order for review, contact the customer, or keep a bad address out of marketing. To refuse a bad address on the storefront itself, the check has to run in your checkout or signup code.

More in E-commerce & payments

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