Skip to main content
hatchmark serve answers a read-only JSON API beside the pages: the dashboards of the last good build, and each block’s numbers in any state a reader can reach on the page, as a block payload your app can draw or read. It needs no setting: the API is on whenever serve runs. To show the blocks as the pages draw them, use the chart elements or React components (Embedding).

Surfaces

The same routes answer under two prefixes. /api/v1 shows what the pages show, to the same people, so it sits behind the same access control (who can see the dashboards). /embed/v1 and the paths under it refuse every request without a valid token, so you can exempt exactly those from a sign-in proxy as you would /mcp, with a rule that stops at the version, such as ^/embed/v1(/|$). Other paths under /embed/ are ordinary pages. A token can read every route; never put one in a browser.

Routes

Every route is a GET (HEAD works too) and answers JSON, except types.d.ts, which answers TypeScript.

Dashboard

  • filters.period, filters.grain and filters.segments: the filter, its options and the value the page shows first.
  • filters.selects: each select filter’s id, label, multiple, selected and every value in options, with listed: true when the filter lists its options and offers no “All”.
  • filters.picks: the categories a reader can pick in a block to filter the others: id, label, the blocks that offer the pick and its options.
  • blocks: each block’s id, kind, heading (title, subtitle), span, height and idFromPosition. A block without id: in its YAML gets one from its position, such as table_3, which changes when blocks move; set id: on blocks an app reads.

Filters

Block and draw routes take the page URL’s filter parameters, checked the same way as hatchmark render --filter (Render to PNG or PDF). Filters you leave out take the dashboard’s defaults. The API answers every state the page can show: each period preset, custom range, segment and select combination and pick the build reached. A state the page can’t reach gets HM6008. Custom ranges and sets of several select values are computed on request from what the build embeds, as the page does in the browser. serve computes one at a time; up to 8 more wait their turn for at most 10 seconds each, and past either limit the request gets HM6007 with Retry-After: 5. Presets and single values never wait.

Block payload

A block payload (hatchmark.block/1) is one block’s render model with everything its renderer reads. Its JSON Schema ships in the package as schema/block-1.schema.json.
  • A number is a number, or null when it is undefined; the page shows that as an em dash. An empty window is a reason such as "no_data", never 0.
  • block.pick lists the keys a reader can pick in the block, in the order it draws them, with the pick filter’s id and label; a key is null where picking it would not apply.
  • state.cleared names a requested pick that the other filters leave with no rows: the payload shows the block without it, as the page drops it.
  • Payloads are the same for the same state of the same build, except freshness.
  • Within block/1, fields and block kinds are only added. Ignore fields you don’t know.
  • A dashboard on which no block reads data, such as a page of text notes, has no as-of date, so its blocks have no payload: the block route answers 404, and types.d.ts leaves them out. Its draw routes still answer.

Draw lists

The draw routes of a block and of the whole dashboard lay the payload out at one width for clients that paint primitives instead of running the renderer, such as a native app. The layout is in the path, so every query parameter stays a filter: For example, /api/v1/dashboards/sales/draw/phone/390?period=last_90_days. KPIs, line, area and bar charts, tables and text have draw lists; other kinds return 400 on the block route and status: "unsupported" in the dashboard’s list.

Caching

Every answer carries a strong ETag and Cache-Control: private, no-cache: clients revalidate with If-None-Match and get 304 while the build and the state are the same. Shared caches don’t store answers, because each one is for a viewer behind your gateway or a token holder.

Calling from another origin

An app on the same origin as serve, such as acme.com/bi/ routed to serve by your gateway, needs no setting: the browser sends the gateway’s cookie. An app on another origin of the same site, such as app.acme.com calling bi.acme.com, needs the gateway’s cookie to cover both hostnames (a cookie domain of .acme.com) and the app’s origin in HATCHMARK_ALLOWED_ORIGINS:
serve then lets that origin read /api/v1 answers with the viewer’s cookies. List origins as scheme, host and port, separated by commas, with no path. Unset, the API answers same-origin only. Requests are plain GETs with no custom headers, so browsers send no preflight. /embed/v1 answers any origin but never reads cookies.

Checks

Errors answer a diagnostic report, the JSON check --json prints, with an HTTP status.