---
name: metabase_create_card
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func MetabaseCreateCard(client MetabaseClient, name string, datasetQuery map[string]any, display string, collectionID int, description string) (map[string]any, error)"
description: "Crea una nueva card/pregunta en Metabase con query SQL nativa o MBQL. Endpoint: POST /api/card."
tags: [metabase, card, question, create, api]
uses_functions: []
uses_types: [MetabaseClient_go_infra]
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [fmt]
params:
  - name: client
    desc: "cliente MetabaseClient autenticado"
  - name: name
    desc: "nombre de la pregunta/card"
  - name: datasetQuery
    desc: "estructura de query SQL nativa o MBQL (structured query)"
  - name: display
    desc: "tipo de visualizacion (table, bar, line, pie, scalar, etc.)"
  - name: collectionID
    desc: "ID de la coleccion destino (0 = root collection)"
  - name: description
    desc: "descripcion de la pregunta o vacio"
output: "mapa con los detalles de la card creada incluyendo su ID"
tested: false
tests: []
test_file_path: ""
file_path: "functions/infra/metabase_create_card.go"
---

## Ejemplo

```go
// Crear pregunta con SQL nativo
card, err := MetabaseCreateCard(client, "Revenue by Month", map[string]any{
    "database": 1,
    "type":     "native",
    "native": map[string]any{
        "query": "SELECT date_trunc('month', created_at) as month, SUM(total) as revenue FROM orders GROUP BY 1 ORDER BY 1",
    },
}, "line", 5, "Monthly revenue trend")

// Crear pregunta con MBQL (structured query)
card, err := MetabaseCreateCard(client, "Order Count", map[string]any{
    "database": 1,
    "type":     "query",
    "query": map[string]any{
        "source-table": 4,
        "aggregation":  []any{[]any{"count"}},
    },
}, "scalar", 0, "Total number of orders")
```

## Notas

### Parametros para un LLM

| Parametro | Tipo | Requerido | Descripcion |
|-----------|------|-----------|-------------|
| client | MetabaseClient | si | Cliente autenticado |
| name | string | si | Nombre de la pregunta |
| datasetQuery | map[string]any | si | Query. Ver estructura abajo |
| display | string | si | Tipo de visualizacion |
| collectionID | int | no | ID de coleccion. 0 = root collection |
| description | string | no | Descripcion. Vacio = sin descripcion |

### Estructura de datasetQuery

**SQL nativo:**
```json
{
  "database": <database_id>,
  "type": "native",
  "native": {"query": "SELECT ..."}
}
```

**MBQL (structured):**
```json
{
  "database": <database_id>,
  "type": "query",
  "query": {
    "source-table": <table_id>,
    "aggregation": [["count"]],
    "breakout": [["field", <field_id>, {"temporal-unit": "month"}]],
    "filter": ["=", ["field", <field_id>, null], "value"]
  }
}
```

### Valores de display

table, bar, line, pie, scalar, area, row, combo, funnel, map, scatter, waterfall, progress, gauge
