danskcvrapi-sdk
v1.0.0
Published
Official JavaScript/TypeScript SDK for DanskCvrApi — typed CvrClient for company lookup, search, financial statements, and statistics from CVR.
Maintainers
Readme
danskcvrapi-sdk
Official TypeScript/JavaScript SDK for DanskCvrApi — a thin, typed wrapper over the REST API for Danish company data from CVR.
No runtime dependencies. Works in Node 18+, Bun, browser (server-side), and edge runtimes.
Installation
npm install danskcvrapi-sdk
# or
bun add danskcvrapi-sdkQuick start
import { CvrClient } from 'danskcvrapi-sdk';
const client = new CvrClient({ apiKey: process.env.CVR_API_KEY! });
// Look up a company
const company = await client.companies.get('24256790');
console.log(company.name, company.industry_text);
// → NOVO NORDISK A/S, Fremstilling af farmaceutiske præparater
// Search
const hits = await client.companies.search({ q: 'novo', limit: 5 });
for (const hit of hits.results) console.log(hit.cvr_number, hit.name);
// Autocomplete (flat array, English fields)
const suggestions = await client.companies.autocomplete({ q: 'novo' });
// [{ cvr, name, city, postal_code, industry, status, production_units }]Create an API key at https://danskcvrapi.dk/dashboard/noegler (Hobby plan is free).
API reference
client.companies
client.companies.get(cvr) // GET /v1/companies/{cvr}
client.companies.search({ q, status?, limit? }) // GET /v1/companies/search
client.companies.autocomplete({ q, limit? }) // GET /v1/companies/autocomplete
client.companies.batch([...cvr]) // POST /v1/companies/batch (Pro+)
client.companies.byAddress({ street, zip_code, … }) // GET /v1/companies/by-address
client.companies.group(cvr) // GET /v1/companies/{cvr}/group
client.companies.roles(cvr) // GET /v1/companies/{cvr}/roles
client.companies.productionUnits(cvr) // GET /v1/companies/{cvr}/production-units
client.companies.history(cvr) // GET /v1/companies/{cvr}/history
client.companies.financialStatements(cvr, { scope? }) // GET /v1/companies/{cvr}/financial-statements (Pro+)client.productionUnits
client.productionUnits.get(pNumber) // GET /v1/production-units/{pnummer}client.persons
client.persons.search({ q, limit? }) // GET /v1/persons/search
client.persons.get(id) // GET /v1/persons/{id}client.replication
client.replication.events({ from_sequence_number, limit? }) // GET /v1/replication/companies/events (Pro+)
client.replication.latestSequenceNumber() // GET /v1/replication/companies/latest-sequence-numberclient.search
client.search.advanced({ industry, municipality, employees_min, … }) // GET /v1/search/advanced (Pro+, 40+ filters)
client.search.netGrowth({ granularity, from, to, … }) // GET /v1/search/net-growth (Pro+)client.stats
client.stats.totals()
client.stats.top({ type?, limit? }) // type: 'industries' | 'municipalities' | 'company-types'
client.stats.byMunicipality() // GET /v1/stats/municipalities
client.stats.byPostalCode() // GET /v1/stats/postal-codes
client.stats.byIndustry({ level? }) // GET /v1/stats/industries (level: 'group' | 'industry')
client.stats.byCompanyType() // GET /v1/stats/company-types
client.stats.foundationsPerYear() // GET /v1/stats/foundations-per-yearclient.creditScore
client.creditScore.get(cvr) // GET /v1/credit-score/{cvr} (Pro+)client.reference
client.reference.industries({ q? }) // GET /v1/industries
client.reference.municipalities() // GET /v1/municipalities
client.reference.regions() // GET /v1/regionsOffline helper
import { validateCvr } from 'danskcvrapi-sdk';
validateCvr('24256790'); // true (modulus-11 check, no API call)Error handling
All calls throw CvrError with type, status, and requestId:
import { CvrError } from 'danskcvrapi-sdk';
try {
await client.companies.financialStatements('24256790');
} catch (err) {
if (err instanceof CvrError && err.type === 'plan_upgrade_required') {
// financial statements require Pro plan
}
if (err instanceof CvrError && err.type === 'not_found') {
// company does not exist
}
}Error types
| type | HTTP status | Meaning |
|---|---|---|
| unauthorized | 401 | Missing or invalid API key |
| forbidden | 403 | Key blocked or workspace suspended |
| not_found | 404 | Resource does not exist |
| invalid_request | 400/422 | Bad parameters |
| rate_limited | 429 | Too many requests |
| plan_upgrade_required | 403 | Endpoint requires a higher plan |
| server_error | 5xx | Server-side error (retried automatically) |
| network | 0 | Network / DNS failure |
Configuration
new CvrClient({
apiKey: '…', // required
baseUrl: '…', // optional URL override (default: https://api.danskcvrapi.dk)
retries: 1, // retries on 5xx/429 (default: 1)
userAgentSuffix: '…', // optional string appended to User-Agent
});Links
- API docs: https://danskcvrapi.dk/docs
- Support: https://danskcvrapi.dk/kontakt
License
MIT
