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.
// 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.
