Developer Guide

Node.js integration guide

A minimal Telebase client in Node.js needs nothing beyond the built-in fetch: URL-encode the phone number, send it with a Bearer token, and parse the JSON response. This page covers that function, the three error responses worth handling explicitly, and why failed lookups should not be retried automatically.

How do you make a lookup call in Node.js?

Use encodeURIComponent to URL-encode the phone number before building the request URL. The + in an E.164 number must become %2B; passing a raw + in a query string is interpreted as a space and will produce a failed or incorrect lookup. encodeURIComponent handles this correctly.

JavaScript
const API_KEY = "tb_test_xxxxxxxxxxxxxxxxxxxxxxxx";
const BASE_URL = "https://app.telebase.io/v1/lookup";

async function lookup(phoneNumber) {
  const encoded = encodeURIComponent(phoneNumber);
  const response = await fetch(`${BASE_URL}?phone=${encoded}`, {
    headers: { Authorization: `Bearer ${API_KEY}` },
  });
  if (!response.ok) {
    throw new Error(`Lookup failed with status ${response.status}`);
  }
  return response.json();
}

const result = await lookup("+447700900001");
console.log(result.carrier, result.numberType, result.simSwap);

How should you handle errors?

fetch does not throw on a non-200 response, it resolves normally, so checking response.ok and branching on response.status is the right place to distinguish the errors your onboarding or authentication flow needs to react to differently.

JavaScript
async function lookup(phoneNumber) {
  const encoded = encodeURIComponent(phoneNumber);
  const response = await fetch(`${BASE_URL}?phone=${encoded}`, {
    headers: { Authorization: `Bearer ${API_KEY}` },
  });

  if (response.status === 401) {
    throw new Error("Missing or malformed API key");
  }
  if (response.status === 400) {
    throw new Error(`Invalid phone number: ${phoneNumber}`);
  }
  if (response.status === 402) {
    throw new Error("Insufficient funds, request a top-up in the dashboard");
  }
  if (!response.ok) {
    throw new Error(`Unexpected status ${response.status}`);
  }
  return response.json();
}

What each status means

Should you retry failed lookups?

No, not automatically. Telebase has no idempotency key, so a repeated request is a new lookup and can be charged again. A 5xx response or a timeout does not prove that the lookup was free, and the provider can take up to 30 seconds to answer. Set a client timeout of at least 35 seconds, and if a request fails or times out, check the Check Log in the dashboard before deciding whether to send another lookup. Every error except 402 and 500 includes "chargedCents": 0.

Never retry 401, 400, 402 or 422 responses: fix the API key, the phone number format or the account balance instead. Retry a 429 only after the retryAfterSeconds it reports.

What does the response contain?

In every response

SIM swap detection

Telebase detects recent SIM swaps with a single API call. See the SIM swap detection API.

New to the API entirely? Start with the quickstart guide for the first request end to end.

Get sandbox access