Integrations / Cookbook and starters
Domain check
How popular each site of a list is, and whether it carries a risk label, as a table or as CSV.
Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)
AvailableTypeScript, Node 22.18+One file, nothing to installTested 2026-11-19
POST /v1/domain takes up to 25 sites and returns, for each, its popularity rank and band and, when it has one, its risk level and categories. The script sends your list in batches of 25 and prints the answers. Useful before you add a site to include_domains, or to vet a list of links.
1Get the code
// Domain check: popularity and risk for a list of sites, as a table (or CSV with --csv).
//
// export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
// node check.ts example.com example.org # or: node check.ts --file sites.txt [--csv]
//
// Node 22.18 or later runs TypeScript as it is; nothing to install. One call per 25 sites, 1 credit each.
import { readFileSync } from 'node:fs';
const API = (process.env.MILLIONSHORT_BASE_URL ?? 'https://api.millionshort.com').replace(/\/$/, '');
type DomainInfo = {
domain: string;
popularity: { rank: number | null; bucket: string };
risk: { level: string; categories: string[] } | null;
};
async function lookUp(domains: string[]): Promise<DomainInfo[]> {
const res = await fetch(`${API}/v1/domain`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ domains }),
});
const body = (await res.json()) as { data?: { domains: DomainInfo[] }; error?: { code: string; message: string } };
if (!res.ok || !body.data) throw new Error(`${body.error?.code ?? res.status}: ${body.error?.message ?? 'no answer'}`);
return body.data.domains;
}
const args = process.argv.slice(2);
const csv = args.includes('--csv');
const fileAt = args.indexOf('--file');
const sites = (fileAt >= 0 ? readFileSync(args[fileAt + 1], 'utf8').split(/\s+/) : args.filter((a) => !a.startsWith('--')))
.map((s) => s.trim().toLowerCase())
.filter(Boolean);
if (!sites.length) {
console.error('usage: node check.ts example.com example.org | --file sites.txt [--csv]');
process.exit(2);
}
const rows: DomainInfo[] = [];
for (let i = 0; i < sites.length; i += 25) rows.push(...(await lookUp(sites.slice(i, i + 25))));
if (csv) {
console.log('domain,rank,popularity,risk,risk_categories');
for (const r of rows) console.log([r.domain, r.popularity.rank ?? '', r.popularity.bucket, r.risk?.level ?? '', (r.risk?.categories ?? []).join(' ')].join(','));
} else {
console.log(`${'Site'.padEnd(32)} ${'Rank'.padStart(9)} ${'Popularity'.padEnd(10)} Risk`);
for (const r of rows) {
const risk = r.risk ? `${r.risk.level} (${r.risk.categories.join(', ')})` : '-';
console.log(`${r.domain.padEnd(32)} ${String(r.popularity.rank ?? '-').padStart(9)} ${r.popularity.bucket.padEnd(10)} ${risk}`);
}
}2Run it
Node 22.18 or later runs TypeScript files as they are:
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
node check.ts example.com github.com obscure-blog-xyz.net
node check.ts --file sites.txt --csv > sites.csv3What you get
Site Rank Popularity Risk
example.com 112 top-1k -
github.com 10 top-100 -
obscure-blog-xyz.net - unknown -A rank of - means the site is outside the top 1,000,000 or we do not know it; its band says which.
4Change it
| To | Change |
|---|---|
| Keep only lesser-known sites | Filter the rows on popularity.bucket === 'long-tail' |
| Drop risky sites from a list | Filter on risk === null |
Costs and limits
1 credit per call of up to 25 sites.
When it fails
| What you see | Why | Fix |
|---|---|---|
401 AUTH_MISSING_KEY or AUTH_INVALID_KEY | The key is missing or wrong | Set MILLIONSHORT_API_KEY; keys start with ms- |
400 INVALID_PARAM | A field name or value the API does not take | The message names the field; the search reference lists them all |
429 RATE_LIMITED or CAPACITY | Too many calls a minute, or no free capacity right now | Wait the Retry-After seconds, then retry |
429 INSUFFICIENT_CREDITS | The plan's credits are used up | Stop and add credits; do not retry |
400 INVALID_PARAM on a long list | More than 25 sites in one call | Keep the batches at 25, as the script does |
Related
- Domain info reference and Popularity and risk.
- Long-tail finder: the same bands, for search results.