Look up a company by CVR number
With cURL you can read the HTTP status code and tell an unknown company apart from a real error.
php
<?php
function get_company(int $cvr): ?array
{
$ch = curl_init("https://apicvr.dk/api/v1/$cvr");
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status === 404) {
return null;
}
if ($status !== 200) {
throw new RuntimeException("CVR-API svarede $status");
}
return json_decode($body, true);
}
$company = get_company(24256790);
echo $company["name"] . ", " . $company["zipcode"] . " " . $company["city"] . PHP_EOL;Search by company name
For quick scripts, file_get_contents is enough. Use rawurlencode so spaces and Danish letters are encoded correctly.
php
<?php
$name = rawurlencode("novo nordisk");
$hits = json_decode(file_get_contents("https://apicvr.dk/api/v1/search/fuzzy/$name"), true);
foreach (array_slice($hits, 0, 5) as $hit) {
echo $hit["cvr_number"] . " " . $hit["name"] . PHP_EOL;
}Handle errors
| Status | Meaning |
|---|---|
200 | The company was found. The body is JSON. |
404 | No company has that CVR number. Body: {"detail": {"error": "NOT_FOUND"}} |
422 | The CVR number isn't a number. |
502 | The CVR register didn't answer. Try again shortly. |
Owners, management and marketing protection
php
<?php
$company = get_company(24256790);
foreach ($company["ejere"] as $owner) {
echo $owner["name"] . " " . $owner["ownership_range"] . PHP_EOL;
}
foreach ($company["direktion"] as $person) {
echo $person["role"] . ": " . $person["name"] . PHP_EOL;
}
if ($company["protected"]) {
echo "Reklamebeskyttet" . PHP_EOL;
}Always check
protected before using the data for marketing. When it's true, the company has opted out of direct marketing.Frequently asked questions
Does it work with Laravel and Symfony?
Yes. Use Laravel's Http::get() or Symfony's HttpClient against the same URL. The response is plain JSON.
Should I cache responses?
Yes, if you look up the same companies often. Company data changes rarely, so caching for a few hours is fine.