Skip to main content
Technical Preview

Overview

A client-mode connector for the Metabase REST API. Use it to push the result of a saved question (OEE per line, scrap by shift, open work orders) onto MQTT for an HMI, andon board or edge display, or to run a short SQL query against any database connected to Metabase when a broker event arrives. Set BASE_ADDRESS to your Metabase URL with no trailing slash and no /api, for example https://metabase.example.com or https://yourcompany.metabaseapp.com on Metabase Cloud. Topics use analytics/metabase/<object>/<verb>; replies land on <topic>/response. See the base guide: REST API Connectors.
Auth: create an API key in Admin settings > Settings > Authentication > API keys (Metabase 49 or later) and send it on the x-api-key header. The key is assigned to a group and has only that group’s data and collection permissions, so create a group with access to just the questions and databases the broker needs. Keep the key in Hub secrets (suggested name METABASE_API_KEY) and never commit it into the .lot. Older versions, or setups without API keys, can sign in with POST /api/session ({"username","password"}) and send the returned id on X-Metabase-Session instead (edit the header in the template).

Basic Syntax

MQTT examples

Every authenticated event reads api_key from the payload. Query events send body as the JSON request body, so the key is never forwarded to Metabase in the body. Health check — publish anything to analytics/metabase/health/get:
Reply on analytics/metabase/health/get/response: {"status":"ok"}. Run a saved question for a display — publish to analytics/metabase/cards/query/json:
Reply (tested on v0.63.19.1 with a question on the Sample Database):
To filter a question that has a field filter or variable, pass parameters, for example {"type": "category", "target": ["variable", ["template-tag", "line"]], "value": "A"}. format_rows: true returns values formatted as in the Metabase UI (dates, currency). Full result with column metadata — publish the same payload to analytics/metabase/cards/query. Metabase answers 202 with {"status":"completed","row_count":4,"data":{"cols":[...],"rows":[["Doohickey",3976,297270.99], ...]}}. Ad-hoc SQL — publish to analytics/metabase/dataset/query:
Reply: 202 with "status":"completed" and data.rows. A failing query returns 400 with "status":"failed" and the database error in error (older Metabase versions answer 202 with "status":"failed", so check status). List saved questions — publish to analytics/metabase/cards/list:

Feeding a display

A small action can republish the latest JSON rows on a retained topic for an HMI. Use PUBLISH TOPIC ... RETAIN, not KEEP TOPIC: KEEP TOPIC stores the value inside the broker only, so the HMI would never receive it.
Trigger the question on a schedule with another action that publishes the request payload to analytics/metabase/cards/query/json (build it with GET SECRET "METABASE_API_KEY" rather than hard-coding the key). Restrict who can read analytics/metabase/# with a rule, because request payloads carry the API key.

Alerts and webhooks (companion, not packaged)

Metabase alerts and dashboard subscriptions can send to a webhook destination (Admin settings > Notification channels > Webhook). Receiving them on the broker needs a separate ENABLE_SERVER REST API connector that accepts a POST on a reachable HTTPS address and publishes the alert payload to MQTT. That companion connector is not part of this template.

Notes

  • /api/card/{id}/query/json is an export endpoint. It returns all rows up to the download row limit, while /api/card/{id}/query and /api/dataset cap results at 2,000 rows. Keep display questions small and aggregated.
  • Unknown card ids return 404 Not found.; a missing or wrong API key returns 401 Unauthenticated.
  • Native SQL through /api/dataset needs native query permission on that database for the key’s group.
  • Metabase API endpoints are not versioned and can change between releases; this template was checked against the OpenAPI spec served by v0.63.19.1 at /api/docs/openapi.json (needs a signed-in user or API key).
  • Not covered: CSV / XLSX exports (/query/csv, /query/xlsx), creating or editing questions and dashboards, pivot queries, embedding and public links.
  • Suggested branches: feat/rest-api-route-metabase, feat/docs-rest-api-metabase (Hugo pushes).
Last modified on October 21, 2026