Bolagsverket Import
Bulk ingestion of the Bolagsverket company registry.
File: src/import/bolagsverket-import.ts.
Source: docs/SYSTEM_OVERVIEW.md § Data imports → Bolagsverket.
Run
bun run src/import/bolagsverket-import.ts data/bolagsverket_bulkfil.txtFormat
- CSV
- latin1-encoded (NOT UTF-8) — must decode accordingly
- Streaming parser
Resume support
Stop and restart safely — the importer deduplicates against existing org_nr values in bolagsverket_companies.
Volume
- 1,794,801 total rows
- 651,611 active companies
- 810,824 rows currently in the DB (per current memory snapshot)
Target schema
CREATE TABLE bolagsverket_companies (
org_nr TEXT UNIQUE NOT NULL,
name TEXT,
legal_form TEXT,
registration_date DATE,
deregistration_date DATE,
business_description TEXT,
address TEXT,
postal_code TEXT,
postal_city TEXT,
is_active BOOLEAN
);See Database Schema.
Live API counterpart
For per-company lookups (not bulk), fetchBolagsverketOrganisation() calls the VärdefullaDatamängder gateway at gw.api.bolagsverket.se. The Öppet API at api.bolagsverket.se is IP-blocked (see Known Issues).
Värdefulla Datamängder API — credentials & access
Warning
These are live API credentials. Do not commit them to the main codebase. Set them in
.envasBV_CLIENT_IDandBV_CLIENT_SECRET.
Credential files
The client_id and client_secret are delivered as a password-protected zip:
| Environment | Zip decryption code |
|---|---|
| Test | uM9LD2amcHyj3p$CMWkw |
| Production | %RV+D7VVHd!kvCYCwt+F |
Zip download (Google Drive): https://drive.google.com/file/d/1X4gaVuB1WZz9NPsOsV6LVgsjcED5zkMk/view?usp=sharing
The zip contains two lines: line 1 = client_id, line 2 = client_secret. Set both in .env:
BV_CLIENT_ID=<line 1 from zip>
BV_CLIENT_SECRET=<line 2 from zip>
OAuth2 token
Grant type: Client Credentials.
curl -X POST https://portal.api.bolagsverket.se/oauth2/token \
-d "grant_type=client_credentials" \
-d "client_id=$BV_CLIENT_ID" \
-d "client_secret=$BV_CLIENT_SECRET" \
-d "scope=vardefulla-datamangder:read"Token endpoint: https://portal.api.bolagsverket.se/oauth2/token
Data endpoint
POST https://gw.api.bolagsverket.se/vardefulla-datamangder/v1/organisationer
Authorization: Bearer <token>
Returns: company name, SNI codes + descriptions, legal form, active status, address, business description.
Developer portal
API specs and sandbox: WSO2 APIM Developer Portal
Where this is used in code
src/fetchers/bolagsverket.ts — fetchBolagsverketOrganisation(orgNr) calls the production endpoint with a cached token. Token refresh is handled automatically.