Skip to content

Sheets & data

Validate emails in a Notion database

A Node.js script with the official Notion SDK reads a database through its data source, verifies each page's Email property and writes an Email status select.

Updated 2026-11-26

This recipe checks the email addresses stored in a Notion database. A Node.js script reads every page whose Email status is empty, verifies its Email property with the API, and writes the result to the page: a select for the status and a text property for the suggested correction or the reason. It uses the official Notion SDK and the current Notion API, which reads rows through data sources. There is no Qelka connection in Notion's gallery: the script runs on your machine, a server or a scheduled job.

What you need

  • A Notion database with an Email property of type Email, an Email status property of type Select and an Email note property of type Text.
  • Workspace Owner rights to create an internal connection, or a personal access token (see step 1).
  • Node.js 22 or later. The current Notion SDK requires it.
  • A Qelka API key. A sk_test_ key returns simulated results and never spends credits: see Test mode. Use a key restricted to email in the dashboard: see Restricted keys.

Steps

1. Create the Notion connection

  1. Open Notion's Developer portal at app.notion.com/developers/connections. On the Developer connections tab, select New connection, give it a name, choose API token as the authentication method and create it.
  2. On the Configuration tab, allow it to read content and update content, then copy the API token.
  3. Give it access to the database: on the Content access tab, select Edit access and pick the database. Or open the database's page in Notion, select the ••• menu, then Connections, and add your connection.

A personal access token works too, for a script only you run. It acts as you, with access to everything you can see, while an internal connection only reaches the pages you share with it. Prefer the connection for anything that runs unattended.

Then copy the data source ID: in the database's settings, open Manage data sources and choose Copy data source ID.

2. Store the secrets

Create a .env file next to the script, and add it to .gitignore:

bash
NOTION_TOKEN=your-notion-api-token
NOTION_DATA_SOURCE_ID=your-data-source-id
QELKA_API_KEY=sk_test_your_key

On a server or in CI, set the same three values as environment variables or secrets instead of a file.

3. The script

Install the SDK:

bash
npm install @notionhq/client
npm pkg set type=module

Save as verify-notion.js:

javascript
import { Client, isFullPage } from '@notionhq/client'

const notion = new Client({
  auth: process.env.NOTION_TOKEN,
  notionVersion: '2026-03-11',
  timeoutMs: 20000,
})
const dataSourceId = process.env.NOTION_DATA_SOURCE_ID
const retryable = new Set([429, 500, 502, 503])

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 {
      console.error('validation skipped: unreachable')
      return null
    }
    if (response.ok) return response.json()
    if (retryable.has(response.status) && attempt < 3) {
      const retryAfter = Number(response.headers.get('Retry-After'))
      await new Promise((resolve) => setTimeout(resolve, (retryAfter > 0 ? Math.min(retryAfter, 10) : attempt * 2) * 1000))
      continue
    }
    const failure = (await response.json().catch(() => null))?.error?.type ?? `http_${response.status}`
    console.error(`validation skipped: ${failure} request ${response.headers.get('X-Request-Id')}`)
    if (failure === 'invalid_api_key' || failure === 'insufficient_credits') process.exit(1)
    return null
  }
  return null
}

async function findUnchecked() {
  const pages = []
  let cursor
  do {
    const response = await notion.dataSources.query({
      data_source_id: dataSourceId,
      start_cursor: cursor,
      filter: {
        and: [
          { property: 'Email', email: { is_not_empty: true } },
          { property: 'Email status', select: { is_empty: true } },
        ],
      },
    })
    for (const page of response.results) {
      if (isFullPage(page)) pages.push(page)
    }
    cursor = response.has_more ? response.next_cursor : undefined
  } while (cursor)
  return pages
}

const pages = await findUnchecked()
let checked = 0
let skipped = 0

for (const page of pages) {
  const property = page.properties['Email']
  const email = property?.type === 'email' ? property.email?.trim() : null
  if (!email) continue
  const result = await verifyEmail(email)
  if (!result) {
    skipped += 1
    continue
  }
  try {
    await notion.pages.update({
      page_id: page.id,
      properties: {
        'Email status': { select: { name: result.status } },
        'Email note': { rich_text: [{ type: 'text', text: { content: result.did_you_mean ?? result.reason } }] },
      },
    })
    checked += 1
  } catch (error) {
    console.error(`notion update failed for ${page.id}: ${error.code ?? error.message}`)
  }
}

console.log(`checked ${checked}, skipped ${skipped}, of ${pages.length} pages`)

Run it with node --env-file=.env verify-notion.js.

What it does, and why:

  • It collects every matching page first, then updates them. Writing a status removes a page from the filter, and changing the result set while paging through it can skip rows.
  • notionVersion: '2026-03-11' opts into Notion's latest API version, which the SDK supports alongside the older 2025-09-03. The calls used here behave the same in both.
  • Notion writes a select option that does not exist yet as a new option, as long as the connection can update the database. Create deliverable, undeliverable, risky and unknown yourself beforehand if you want to choose their colors.
  • The email check runs in the default full mode, mailbox check included, with a 15-second timeout: nothing waits on this script, so it can afford the most precise answer. See the email reference.
  • A failed check writes nothing, so the page is picked up again next run. A wrong key or an empty balance stops the script at once instead of skipping every page.

4. Schedule it

Run the script from cron, a scheduled job on your platform, or a GitHub Actions workflow on a schedule, with the three secrets set there. Each run only checks pages added since the last one, so an hourly run costs nothing when nothing is new.

Use the status

Email status Meaning What to do
deliverable The mail server accepted the mailbox Use it
undeliverable Bad syntax, no domain or no mailbox Fix it with Email note when it holds a suggestion, or find another address
risky Disposable inbox, catch-all domain or full mailbox Read the reason in Email note before writing to it
unknown The checks could not conclude Keep it: not a bad address
Empty Not checked yet, or the check failed Wait for the next run

Add a filtered view on Email status is undeliverable to review bad addresses, or group a board by the status.

Handle errors and rate limits

Nothing is billed on errors. The script retries 429, 500, 502 and 503 after Retry-After, then logs the error type and the X-Request-Id and moves to the next page. 401 invalid_api_key and 402 insufficient_credits stop the run, since every other page would fail the same way. A key allows 200 requests per 10 seconds, and each email check costs 1 credit. See Errors and Rate limits.

Notion is usually the slower side. It limits the request rate of each connection, more tightly on plans below Business, and answers 429 rate_limited with a Retry-After header beyond it. The Notion SDK retries rate-limited requests on its own, twice by default, and a query returns at most 10,000 pages, by Notion's current limits. For a database of tens of thousands of rows, export the emails to CSV and run a bulk job instead, then import the statuses back.

Frequently asked questions

Why does the script need a data source ID instead of a database ID?
Since Notion API version 2025-09-03, a database is a container for one or more data sources, and rows are queried from a data source with dataSources.query. The old databases.query call belongs to earlier versions. Copy the ID from the database's settings, under Manage data sources, or read it from the data_sources list that databases.retrieve returns.
Will the script check the same rows every time it runs?
No. It asks Notion only for pages whose Email is set and whose Email status is empty, and it writes a status only when the check ran. A page whose check failed keeps an empty status, so the next run picks it up again. To re-check an old row, clear its Email status.
Can new rows be checked automatically?
Run the script on a schedule, for example every hour with cron or a GitHub Actions workflow: it only spends credits on new rows. For checks within seconds of a row being added, a Notion database automation with a webhook action can call a small function of yours that runs the same code for one page. Automations depend on your Notion plan, so check yours.

More in Sheets & data

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