CVR lookups in JavaScript

CVR-API sends CORS headers, so you can call it straight from the browser. The same code works in Node.js 18 and later, where fetch is built in.

Look up a company by CVR number

javascript
async function getCompany(cvr) {
  const res = await fetch(`https://apicvr.dk/api/v1/${cvr}`);
  if (res.status === 404) return null;
  if (!res.ok) throw new Error(`CVR-API svarede ${res.status}`);
  return res.json();
}

const company = await getCompany(24256790);
console.log(company.name, company.zipcode, company.city);

getCompany returns null when the CVR number doesn't exist (404). Any other error throws.

Search by company name

Fuzzy search works well for autocomplete. Remember to encodeURIComponent the name.

javascript
async function searchCompanies(name) {
  const res = await fetch(`https://apicvr.dk/api/v1/search/fuzzy/${encodeURIComponent(name)}`);
  if (!res.ok) throw new Error(`CVR-API svarede ${res.status}`);
  return res.json();
}

const hits = await searchCompanies("novo nordisk");
for (const hit of hits.slice(0, 5)) {
  console.log(hit.cvr_number, hit.name, "-", hit.industrytext);
}
If you search from an input field, wait about 300 ms after the last keystroke (debounce) before calling the API.

Handle errors

StatusMeaning
200The company was found. The body is JSON.
404No company has that CVR number. Body: {"detail": {"error": "NOT_FOUND"}}
422The CVR number isn't a number.
502The CVR register didn't answer. Try again shortly.

Owners, management and marketing protection

javascript
const { ejere, direktion, protected: isProtected } = await getCompany(24256790);

for (const owner of ejere) {
  console.log(owner.name, owner.ownership_range);
}
for (const person of direktion) {
  console.log(person.role, person.name);
}
if (isProtected) {
  console.log("Reklamebeskyttet");
}
Always check protected before using the data for marketing. When it's true, the company has opted out of direct marketing.

Frequently asked questions

Can I call CVR-API directly from the browser?

Yes. The API allows CORS from any origin, so you don't need a proxy.

Do the examples work in Node.js?

Yes, in Node.js 18 and later, where fetch is built in. On older versions you can use the node-fetch package.

Can I use it with TypeScript?

Yes. The full OpenAPI specification is at /openapi.json, so you can generate types from it.