Skip to content

Integrations

Validate phone numbers and emails in Shopify

Check the email and phone of each new Shopify customer with a signed customers/create webhook, the SDK and the Admin GraphQL API, and tag customers by result.

Updated 2026-11-23

This recipe checks the email and phone of each new Shopify customer. A signed webhook calls a small receiver, the receiver calls the API, and the result comes back to the customer as tags. Shopify has no native Qelka integration, so the receiver sits in between.

What you need

  • A Shopify store and a custom app with the write_customers scope and a customers/create webhook subscription.
  • A Qelka API key in the API_KEY environment variable. A sk_test_ key returns simulated results and never spends credits: see Test mode.
  • A server reachable over HTTPS for the webhook, with SHOPIFY_CLIENT_SECRET, SHOPIFY_ADMIN_TOKEN, SHOPIFY_SHOP (for example my-store.myshopify.com) and SHOPIFY_API_VERSION (a supported Admin API version) set: see Authentication.

Steps

1. The receiver

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

const client = new Client({ apiKey: process.env.API_KEY, timeoutMs: 8000 })
const app = express()

function signatureIsValid(rawBody, header) {
  if (!header) return false
  const expected = crypto.createHmac('sha256', process.env.SHOPIFY_CLIENT_SECRET).update(rawBody).digest('base64')
  const received = Buffer.from(header)
  const wanted = Buffer.from(expected)
  return received.length === wanted.length && crypto.timingSafeEqual(received, wanted)
}

async function addTags(customerGid, tags) {
  const response = await fetch(`https://${process.env.SHOPIFY_SHOP}/admin/api/${process.env.SHOPIFY_API_VERSION}/graphql.json`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'X-Shopify-Access-Token': process.env.SHOPIFY_ADMIN_TOKEN },
    body: JSON.stringify({
      query: 'mutation($id: ID!, $tags: [String!]!) { tagsAdd(id: $id, tags: $tags) { userErrors { message } } }',
      variables: { id: customerGid, tags },
    }),
  })
  const result = await response.json()
  const errors = result.data?.tagsAdd?.userErrors ?? []
  if (!response.ok || errors.length > 0) console.error('tagging failed', response.status, JSON.stringify(errors))
}

app.post('/shopify/customers-create', express.raw({ type: '*/*' }), async (req, res) => {
  if (!signatureIsValid(req.body, req.get('X-Shopify-Hmac-Sha256'))) return res.sendStatus(401)
  res.sendStatus(200)

  const customer = JSON.parse(req.body.toString('utf8'))
  const gid = customer.admin_graphql_api_id
  const phone = customer.phone ?? customer.default_address?.phone
  const country = customer.default_address?.country_code
  const tags = []

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

  await Promise.all([
    customer.email &&
      settle(async () => {
        const result = await client.email.verify({ email: customer.email })
        if (result.status === 'undeliverable') tags.push('email-undeliverable')
        else if (result.status === 'risky') tags.push(result.reason === 'disposable' ? 'email-disposable' : 'email-risky')
      }),
    phone &&
      settle(async () => {
        const result = await client.phone.validate({ phone, country })
        if (result.status === 'invalid') tags.push('phone-invalid')
      }),
  ])

  if (tags.length > 0) await addTags(gid, tags)
})

app.listen(3000)

The receiver answers 200 first, so Shopify does not retry while the checks run, and it tags only on a clear signal: an unknown result or a failed call adds nothing, which is the same as passing. Shopify expects an answer within a few seconds, so never wait for the API before replying.

2. Subscribe to the webhook

Subscribe the app to customers/create with the HTTPS URL of the receiver, for example https://example.com/shopify/customers-create, in the app configuration or with the webhook subscription API. The exact screens and the supported API versions change, so follow the current Shopify documentation. Create a test customer and check that the tag appears.

3. Act on the tags

Tag Meaning Suggested action
email-undeliverable Bad syntax, no domain or no mailbox Exclude from marketing emails, ask the customer to correct it
email-disposable Throwaway inbox Review, or exclude from marketing lists
email-risky Catch-all domain or full mailbox Send, but watch the bounces
phone-invalid The number does not fit its country's numbering plan Do not use it for SMS

Use customer segments on these tags to keep bad addresses out of campaigns. For the customers you already have, export them and run a bulk file check instead of calling the webhook for each. See the email reference and the phone reference.

Handle errors and rate limits

No error is billed. The SDK retries 429, 502 and 503 responses, waiting Retry-After when present. After 200 requests per 10 seconds on one key you get 429 rate_limited. 401 invalid_api_key and 403 forbidden mean a wrong or restricted key. 402 insufficient_credits means an empty balance: alert yourself and keep failing open. Each email check costs 1 credit. See Errors and Rate limits.

Frequently asked questions

Why tag customers instead of blocking them?
A customers/create webhook fires after the customer exists, so the check cannot stop the signup. Tagging gives you something to act on: a Shopify Flow, a customer segment or a marketing list can exclude customers tagged as bad email, and your team can review the risky ones.
How do I trust the webhook?
Shopify signs each webhook with an HMAC-SHA256 of the raw body, using the app client secret, and sends it base64 encoded in the X-Shopify-Hmac-Sha256 header. Compute the same value over the raw bytes and compare in constant time before you read the body. Reject anything that does not match.
What access does the app need?
A custom app, created in the Shopify admin or the Dev Dashboard, with the write_customers access scope so it can add tags, and a webhook subscription to customers/create. The Admin API access token and the client secret go in environment variables on your server, never in a theme or in client code.

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