# Datapublica Business Register API

Use structured Danish Central Business Register data in applications, analyses, and automated workflows. The official API is JSON over HTTPS and is hosted at `https://query.datapublica.dk`.

Public API credentials are available on paid Datapublica plans. Connecting an
MCP client requires a Datapublica account, with full MCP access on a paid plan.

## Quickstart

### 1. Create a personal API token

Sign in to a paid [Datapublica](https://datapublica.dk/login) account, open [App settings](https://datapublica.dk/app/settings), and create an API token. Each user can have one active token. The settings page shows the active token and lets you revoke it; revoke the current token before creating a new one.

Keep the token on the server side. Do not place it in browser code, source control, logs, or public agent prompts.

### 2. Make your first request

Set the token in your shell and request company search results:

```bash
export DATAPUBLICA_API_TOKEN="your-token"

curl --get 'https://query.datapublica.dk/api/companies/search' \
  --header "Authorization: Bearer $DATAPUBLICA_API_TOKEN" \
  --data-urlencode 'q=chr' \
  --data-urlencode 'limit=1'
```

A successful response has the search metadata and result rows:

```json
{
  "query": "chr",
  "total": 40551,
  "limit": 1,
  "offset": 0,
  "rows": [
    {
      "cvr_number": "14748105",
      "company_name": "CHRISTOFFERSEN & KNUDSEN A/S",
      "city": "Rødovre",
      "is_active": true
    }
  ]
}
```

Search totals and rows reflect the active dataset build.

### 3. Call the API with `fetch`

```js
const url = new URL("https://query.datapublica.dk/api/companies/search");
url.searchParams.set("q", "chr");
url.searchParams.set("limit", "1");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.DATAPUBLICA_API_TOKEN}`,
  },
});

if (!response.ok) {
  throw new Error(`Datapublica request failed: ${response.status}`);
}

const result = await response.json();
console.log(result.rows);
```

### 4. Ask a question in natural language

Translate a question into read-only SQL, then execute the returned SQL. Reusing the same `x-request-id` with `source=natural-language` and the original question keeps both calls on one natural-language usage reservation:

```bash
REQUEST_ID="$(uuidgen)"
QUESTION="Companies with the highest revenue in 2025"

curl 'https://query.datapublica.dk/api/sql/translate' \
  --request POST \
  --header "Authorization: Bearer $DATAPUBLICA_API_TOKEN" \
  --header "x-request-id: $REQUEST_ID" \
  --header 'Content-Type: application/json' \
  --data "{\"query\":\"$QUESTION\",\"locale\":\"en\",\"maxRows\":10}"
```

A successful translation returns `status: "ok"` with the generated `sql` plus a description, notes, and assumptions. Copy the `sql` value and execute it:

```bash
TRANSLATED_SQL='SELECT ... FROM gold.mart_company_financials_annual ... LIMIT 10'

curl --get 'https://query.datapublica.dk/api/sql' \
  --header "Authorization: Bearer $DATAPUBLICA_API_TOKEN" \
  --header "x-request-id: $REQUEST_ID" \
  --data-urlencode 'source=natural-language' \
  --data-urlencode "rawInput=$QUESTION" \
  --data-urlencode "query=$TRANSLATED_SQL"
```

A `422` response means the question needs clarification or asks for something unsupported — revise the question instead of executing SQL. See [`POST /api/sql/translate`](/docs/api#post-api-sql-translate) for the full contract.

## What is in v1

The official API covers authenticated company/person/participant search and detail data, timelines, ownership portfolios and relation expansion, read-only SQL, and natural-language-to-SQL translation.

- [API reference](/docs/api)
- [Authentication](/docs/api/authentication)
- [Connect an agent (MCP)](/docs/mcp)
- [Errors and freshness](/docs/errors)
- [OpenAPI 3 document](/docs/openapi.json)
- [Agent API bundle](/docs/agents/api.md)

The reference endpoint index is exhaustive. Do not construct or rely on endpoints that are absent from it.

## Markdown-first documentation

Every core docs page returns raw Markdown when `text/markdown` is preferred:

```bash
curl --header 'Accept: text/markdown' https://datapublica.dk/docs/api
```

Stable raw files are also available:

- [Overview Markdown](/docs/index.md)
- [API reference Markdown](/docs/api.md)
- [Authentication Markdown](/docs/api/authentication.md)
- [MCP getting started Markdown](/docs/mcp.md)
- [Errors Markdown](/docs/errors.md)
- [Agent API bundle](/docs/agents/api.md)

## Support

For API questions or feedback, use the [support page](https://datapublica.dk/support). Include the request URL, HTTP status, and `x-request-id` response header when reporting a failed request. Never send your API token.
