COMPANYAPI

CompanyAPI with Node.js.

A server-side fetch example with a timeout and explicit error handling.

Before you start

Use Node.js 22 or later. Set COMPANYAPI_KEY in your environment. Never prefix a secret with NEXT_PUBLIC_ or send it to browser code.

Make the request

This example returns null for 404, rejects other non-success statuses and cancels after ten seconds. Run it on your server.

JavaScript
// Node.js 22+. Server-side only.
const key = process.env.COMPANYAPI_KEY;
if (!key) throw new Error('Set COMPANYAPI_KEY');

async function company(number) {
  const response = await fetch(
    'https://api.companyapi.be/companies/' + encodeURIComponent(number),
    { headers: { 'X-Api-Key': key }, signal: AbortSignal.timeout(10000) }
  );
  if (response.status === 404) return null;
  if (!response.ok) {
    // Handle 429 with bounded backoff. Do not retry 400 or 401.
    throw new Error('CompanyAPI HTTP ' + response.status);
  }
  return response.json();
}

console.log(await company('0801523965'));

Take it into production

Add bounded retries for transient failures, safe logging and your application’s field mapping. API keys and company lookup values should not enter analytics.

COMPANYAPI

Build your next connection.

Start with a free API key. Give your application a better foundation.

Get an API key

We save your privacy choice. With your permission, we remember your language, measure visits with Umami, and record interactions for session replays and heatmaps. Each optional purpose is off until you choose.

No advertising trackers. Change or withdraw your choices at any time using Cookie preferences.