Upstream quirks
Behavior of the kanalregister DBH API as it serves the tables today. The client absorbs most of this; the rest is worth knowing before you query.
The DBH query language
Every query is a JSON body with at least one filter clause. Only
tabell_id and api_versjon are obligatory, but the API rejects a body
with an empty filter list, so search() without filters sends a
match-all clause ({"filter": "all", "values": ["*"]}) on the resource's
default variable. The selection kinds are all, item, between,
like, top, greaterthan, and lessthan, and every clause carries an
optional exclude list. values travel as strings even for years and
ids: pass "2024", not 2024.
The date filter on Sist endret takes the spelling Jan 23 2026
(documented examples), not ISO dates. A bad variable name in a filter
answers HTTP 400 with text/plain that echoes the request body instead
of naming the problem.
Answers
- The JSON route (
hentJSONTabellData) answers a bare list of records, no envelope. Withstatuslinje: "J"in the body the list gains a leading status record with astatuskey; the client omits the key and never sees it. - A query that matches no rows answers HTTP 204 with no body, not an
empty JSON list. The client reads a 204 as an empty list, so
search()returns an empty page,get()raisesNotFoundError, andexists()returnsFalse. - Every column name carries spaces and Norwegian letters (
"Tidsskrift id","Nivå 2026","ISBN-prefix"). The models map them with pydantic aliases. Absent cells are JSONnullon the JSON route and""on the CSV routes; both becomeNonein the models. - The
Nivå <year>columns of tables 850 and 851 grow one column per year. The models keep them as extra fields and thelevelsproperty gathers them into one mapping keyed by year. - The per-year level tables 852 and 853 also carry rows for channels
that were never assessed: one row per channel with empty
ÅrandNivåcells, which becomeNone. Level values are"0","1","2", and"X". Sist endrethas two wire spellings:Nov 2 2026 7:49AMon the query routes and09-Oct-2026 13:50:46on thebulk-csvsnapshots. The models keep the string, so one field can carry both.- Answers keep no total count anywhere.
search()returnsPagewithtotal=None, and there is no paging: every query answer carries the full result list.
CSV shapes
- The
bulk-csvsnapshots (GET bulk-csv?rptNr=<id>) are comma-separated with one header row and no BOM. The query CSV route (hentCSVTabellData) is semicolon-separated and puts a preamble of#-prefixed status lines (#tabell_id,#antall,#returkode,#melding) before the header; one status line shows a mangled#leveringstidvalue (342026-11-30 18:34:42"). The client skips the preamble.iter_table_csv()reads the snapshots;search_csv()parses the query route. - Rows always match the header width, but the client pads short rows and drops surplus cells anyway, the way the files can drift.
Errors and limits
- A whole-table query for table 853 answers about 36 MB of rows; the
bulk-csvsnapshot for it can exceed the gateway timeout. A retry succeeds. Preferbulk-csv(which the client uses) over a match-all query for that table. - Asking for a table number that is not a BULK table answers HTTP 501
with the message
Tabell er ikke BULK tabell(bulk-csvonly serves tables HK-dir exports that way). - The two streaming variants
streamCsvDataandstreamJsonDataserve the same query data in the same shapes; the client does not wrap them. - The health route (
GET /api/krtabeller/) answers a plain text status line, not data.