Skip to content

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. With statuslinje: "J" in the body the list gains a leading status record with a status key; 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() raises NotFoundError, and exists() returns False.
  • Every column name carries spaces and Norwegian letters ("Tidsskrift id", "Nivå 2026", "ISBN-prefix"). The models map them with pydantic aliases. Absent cells are JSON null on the JSON route and "" on the CSV routes; both become None in the models.
  • The Nivå <year> columns of tables 850 and 851 grow one column per year. The models keep them as extra fields and the levels property 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 År and Nivå cells, which become None. Level values are "0", "1", "2", and "X".
  • Sist endret has two wire spellings: Nov 2 2026 7:49AM on the query routes and 09-Oct-2026 13:50:46 on the bulk-csv snapshots. The models keep the string, so one field can carry both.
  • Answers keep no total count anywhere. search() returns Page with total=None, and there is no paging: every query answer carries the full result list.

CSV shapes

  • The bulk-csv snapshots (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 #leveringstid value (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-csv snapshot for it can exceed the gateway timeout. A retry succeeds. Prefer bulk-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-csv only serves tables HK-dir exports that way).
  • The two streaming variants streamCsvData and streamJsonData serve 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.