metabase-api-skill

psh-inc 的头像作者 psh-inc

添加、管理和执行SQL脚本。支持创建卡片/问题、运行查询和管理集合。用于:程序化创建Metabase仪表板、自动化报告生成、通过API管理SQL问题/卡片或集成Metabase与平台。

📖 中文导读:添加、管理和执行SQL脚本。支持创建卡片/问题、运行查询和管理集合。用于:程序化创建Metabase仪表板、自动化报告生成、通过API管理SQL问题/卡片或集成Metabase与平台。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: metabase-api-skill description: | Add, manage, and execute SQL scripts in self-hosted Metabase via REST API. Supports creating cards/questions, running queries, and managing collections. Use when: Creating Metabase dashboards programmatically, automating report generation, managing SQL questions/cards via API, or integrating Metabase with the casino platform. allowed-tools: Read, Edit, Write, Glob, Grep, Bash

Metabase API Skill

This skill covers programmatic interaction with Metabase's REST API for the casino platform. Use it for creating SQL-based cards (questions), managing collections, running ad-hoc queries, and automating dashboard creation. The casino platform uses Metabase for affiliate reporting (CellExpert metrics), player analytics, and transaction reporting.

Quick Start

Authentication

# Get session token
curl -X POST https://metabase.example.com/api/session \
  -H "Content-Type: application/json" \
  -d '{"username": "admin@casino.com", "password": "secret"}'

# Response: {"id": "session-token-here"}

Create a SQL Card

curl -X POST https://metabase.example.com/api/card \
  -H "Content-Type: application/json" \
  -H "X-Metabase-Session: ${SESSION_TOKEN}" \
  -d '{
    "name": "Player Deposits by Currency",
    "dataset_query": {
      "type": "native",
      "native": {
        "query": "SELECT currency, SUM(amount) as total FROM transactions WHERE type = '\''DEPOSIT'\'' GROUP BY currency",
        "template-tags": {}
      },
      "database": 1
    },
    "display": "bar",
    "visualization_settings": {},
    "collection_id": 5
  }'

Key Concepts

Concept Usage Example
Card A saved question/query SQL or GUI-based query
Collection Folder for organizing cards collection_id: 5
Database Connected data source PostgreSQL casino DB
Dashboard Container for multiple cards Player Overview
Template Tags Parameterized queries {{player_id}}

Common Patterns

Execute Ad-hoc Query

When: Running one-off queries for debugging or data exploration

curl -X POST https://metabase.example.com/api/dataset \
  -H "Content-Type: application/json" \
  -H "X-Metabase-Session: ${SESSION_TOKEN}" \
  -d '{
    "database": 1,
    "type": "native",
    "native": {
      "query": "SELECT * FROM players WHERE id = {{player_id}}",
      "template-tags": {
        "player_id": {"type": "number", "name": "player_id", "display-name": "Player ID"}
      }
    },
    "parameters": [{"type": "number", "target": ["variable", ["template-tag", "player_id"]], "value": 12345}]
  }'

List Collections

When: Finding where to place new cards

curl -X GET https://metabase.example.com/api/collection \
  -H "X-Metabase-Session: ${SESSION_TOKEN}"

See Also

  • patterns - Card creation, query optimization, error handling
  • workflows - Dashboard automation, report scheduling
  • See the postgresql skill for SQL query optimization and schema design
  • See the spring-boot skill for backend API integration with Metabase