One npm package for 128 data APIs

dataandapis is the official JavaScript and TypeScript client for the catalog. Every API is a property of the client and every endpoint is a typed method, so your editor completes the call and you never build a URL by hand.

npm install dataandapis
  • Version 0.1.0
  • MIT licence
  • No dependencies
  • import and require
  • Node.js 18 or later
index.ts
import { DataAndApis } from "dataandapis";

// reads DATAANDAPIS_API_KEY from the environment
const client = new DataAndApis();

const check = await client.vat.validateVatNumber({
  vat: "IE6388047V",
});

console.log(check.valid, check.name);
// true "GOOGLE IRELAND LIMITED"

Install

npm install dataandapis

With another package manager:

pnpm add dataandapis
yarn add dataandapis
bun add dataandapis

Quick start

Create a free account and generate a key on your dashboard. The Free plan includes 500 tokens a month and needs no card; most calls cost 1 token. Get a free API key →

ES modules and TypeScript
import { DataAndApis } from "dataandapis";

const client = new DataAndApis({ apiKey: process.env.DATAANDAPIS_API_KEY });

const check = await client.vat.validateVatNumber({ vat: "IE6388047V" });
console.log(check.valid, check.name); // true "GOOGLE IRELAND LIMITED"
CommonJS
const { DataAndApis } = require("dataandapis");

const client = new DataAndApis({ apiKey: process.env.DATAANDAPIS_API_KEY });

client.vat.validateVatNumber({ vat: "IE6388047V" }).then((check) => {
  console.log(check.valid, check.name);
});

If you leave apiKey out, the client reads the DATAANDAPIS_API_KEY environment variable.

How calls are named

The property is the API's address on this site in camelCase, so /apis/barcode-lookup is client.barcodeLookup. The method is the endpoint's name, so Lookup By Barcode is lookupByBarcode.

Path and query parameters go in one object. A JSON body goes in body.

// GET /v1/products/{barcode}: the path parameter goes in the object
const product = await client.barcodeLookup.lookupByBarcode({ barcode: "3017620422003" });

// Query parameters go in the same object
const result = await client.sanctions.screenName({ name: "Viktor Bout", min_score: 0.85 });

// POST: the JSON body goes in "body"
const batch = await client.sanctions.screenNamesBatch({
  body: { names: ["Viktor Bout", "Acme Trading LLC"] },
});

Every API page shows the exact call for each of its endpoints, ready to copy.

Errors

Every failure is an instance of DataAndApisError, with one class per case.

ClassWhen
AuthenticationError401: the key is missing or not valid
PaymentRequiredError402: the subscription is past due; paymentUrl holds the link to pay
QuotaExceededError429: the monthly token allowance is used up
ApiErrorAny other error status, such as 400 or 404
TimeoutErrorNo response within the timeout
ConnectionErrorThe request never got a response
import { ApiError, DataAndApis, QuotaExceededError } from "dataandapis";

try {
  await client.barcodeLookup.lookupByBarcode({ barcode: "0000000000000" });
} catch (err) {
  if (err instanceof QuotaExceededError) {
    // upgrade the plan or wait for the monthly reset
  } else if (err instanceof ApiError && err.status === 404) {
    console.log("Not in the catalogue:", err.message);
  } else {
    throw err;
  }
}

Retries, timeouts and token balance

GET requests are retried up to twice after a network error or a 408, 502, 503 or 504 response. POST requests and 429 responses are never retried. Each attempt has a 30 second timeout. Both numbers can be changed for the client or for one call. Failed calls do not use tokens.

Every response reports how many tokens are left on your key, and onResponse receives that number.

const client = new DataAndApis({
  timeout: 30_000, // milliseconds per attempt
  maxRetries: 2,   // retries for GET requests
  onResponse: ({ api, status, tokensRemaining }) => {
    if (tokensRemaining !== undefined && tokensRemaining < 50) console.warn("Running low on tokens");
  },
});

// Or for one call
await client.vat.validateVatNumber({ vat: "FR40303265045" }, { timeout: 45_000, maxRetries: 0 });

Endpoints that return a file

Image and document endpoints resolve to a Blob.

import { writeFile } from "node:fs/promises";

const png = await client.qrCodeGenerator.generateQrCode({ data: "https://dataandapis.com", size: 400 });
await writeFile("qr.png", Buffer.from(await png.arrayBuffer()));

TypeScript

Types ship with the package. Response types are inferred from one sample response per endpoint, so treat them as a guide: a field can be null or missing for other inputs. Pass your own type as a type argument when you need a stricter one.

interface Holiday {
  date: string;
  name: string;
}

const next = await client.publicHolidays.nextHolidays<{ holidays: Holiday[] }>({ country: "MX" });

// Every parameter and response type is exported
import type { VatValidateVatNumberParams, VatValidateVatNumberResponse } from "dataandapis";

Where it runs

Node.js 18 or later; the tests run on Node.js 18, 20, 22 and 25. The package only needs the built-in fetch, so Bun, Deno and Cloudflare Workers should work as well, although they are not part of the test run.

Call the APIs from your server. They do not send CORS headers, so the browser blocks requests from a web page, and a key in front-end code would be visible to every visitor.

All 128 APIs in the package

Version 0.1.0 covers 128 APIs and 529 endpoints. Search for an API to see its name on the client.

Not using JavaScript?

Every API is plain REST with an X-Api-Key header, so any HTTP client works. Each API page has samples in Python, PHP and Go and an OpenAPI 3.1 document.