Integrations
Validate phone numbers and emails in Node.js
Check phone numbers, emails and IPs from Node.js with the official SDK or plain fetch. Read the result, block or flag signups and handle errors and rate limits.
Updated 2026-11-23
This recipe adds email, phone and IP checks to a Node.js service. You call the API from your server, read a few fields of the result, and decide whether to accept, reject or flag the signup.
What you need
- Node.js 20 or later. The SDK and the examples use the built-in
fetch. - A Qelka API key. A
sk_test_key is enough while you build: it returns simulated results and never spends credits. See Test mode. - The key in an environment variable named
API_KEY. Never put it in source code, and never call the API from browser code: see Authentication.
Check your balance and plan on the pricing page. A live email check costs 1 credit and a basic phone check costs 1 credit.
Steps
1. Install the SDK
npm install @qelka/sdk
2. Verify one email and one phone number
import { ApiConnectionError, ApiError, Client } from '@qelka/sdk'
const client = new Client({ apiKey: process.env.API_KEY, timeoutMs: 8000 })
export async function checkSignup({ email, phone, country }) {
const errors = []
let checked = true
try {
const result = await client.email.verify({ email })
if (result.status === 'undeliverable') {
errors.push({
field: 'email',
message: result.did_you_mean ? `Did you mean ${result.did_you_mean}?` : 'This email address cannot receive mail.',
})
}
} catch (error) {
checked = handleFailure(error)
}
try {
const result = await client.phone.validate({ phone, country })
if (result.status === 'invalid') {
errors.push({ field: 'phone', message: 'This phone number is not valid.' })
}
return { ok: errors.length === 0, errors, checked, e164: result.e164 }
} catch (error) {
checked = handleFailure(error)
return { ok: errors.length === 0, errors, checked, e164: null }
}
}
function handleFailure(error) {
if (error instanceof ApiConnectionError) return false
if (!(error instanceof ApiError)) throw error
console.error(error.type, error.status, error.requestId)
if (error.type === 'invalid_request' || error.type === 'unprocessable_input') return true
return false
}
email.verify returns status (deliverable, undeliverable, risky or unknown), a reason and did_you_mean. phone.validate returns status (valid, invalid or unknown) and e164. The unknown phone status means the number had no + prefix and you sent no country. See the email reference and the phone reference.
3. Flag risky signups with the IP
export async function reviewIp(ip) {
try {
const result = await client.ip.lookup({ ip })
return result.risk.level === 'high' || result.flags.tor
} catch (error) {
if (error instanceof ApiError && error.type === 'unprocessable_input') return false
throw error
}
}
A 422 unprocessable_input means a private or loopback address, which is what your server sees in local development. Treat it as "no signal". A high risk level is a reason to ask for extra verification, not to refuse the person.
4. The same calls with plain fetch
const retryable = new Set([429, 500, 502, 503])
const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))
export async function callApi(path, body, maxAttempts = 4) {
for (let attempt = 1; ; attempt += 1) {
const response = await fetch(`https://api.qelka.com/v1${path}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
signal: AbortSignal.timeout(8000),
})
if (response.ok) return response.json()
const failure = (await response.json()).error
const retryAfter = Number(response.headers.get('Retry-After'))
if (!retryable.has(response.status) || attempt === maxAttempts) {
const error = new Error(`${failure.type}: ${failure.message}`)
error.type = failure.type
error.requestId = response.headers.get('X-Request-Id')
throw error
}
await sleep(retryAfter > 0 ? retryAfter * 1000 : 1000 * 2 ** (attempt - 1) + Math.random() * 250)
}
}
const email = await callApi('/email', { email: 'jane@example.com' })
console.log(email.status, email.reason)
5. Decide what to do with each answer
| Result | Action |
|---|---|
Email undeliverable |
Reject and show did_you_mean when present |
Email risky |
Accept and flag, or reject if you block disposable inboxes |
Email unknown |
Accept. Do not treat it as bad |
Phone valid |
Store e164, not what was typed |
Phone invalid |
Ask the person to check the number |
IP high risk or Tor |
Flag the account for review |
Handle errors and rate limits
No error is billed. 401 invalid_api_key and 403 forbidden mean a bad or restricted key: fix the key, do not retry. 402 insufficient_credits means your balance is empty: alert yourself and fail open. 429 rate_limited means you passed 200 requests per 10 seconds for the key: wait Retry-After seconds. The SDK does this for you. For files or many values, use POST /batch or bulk jobs instead of looping. Log the X-Request-Id with every failure. Errors lists all nine types.
Store each result next to the record, so you never check the same value twice.
Related
Frequently asked questions
Should I use the SDK or plain fetch in Node.js?
Which Node.js version do I need?
Should an API outage block my signup form?
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