---
name: metabase_create_card_alert
kind: function
lang: py
domain: infra
version: "1.0.0"
purity: impure
signature: "def metabase_create_card_alert(client: MetabaseClient, card_id: int, cron_schedule: str, recipients: list[dict], send_condition: str = 'has_result', send_once: bool = False) -> dict"
description: "Crea una alerta sobre los resultados de una card en Metabase. Envia email segun cron cuando la card cumple la condicion (has_result, goal_above, goal_below). Endpoint: POST /api/notification."
tags: [metabase, notification, alert, card, create, api, python]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
params:
  - name: client
    desc: "instancia autenticada de MetabaseClient"
  - name: card_id
    desc: "ID de la card que dispara la alerta"
  - name: cron_schedule
    desc: "expresion cron de 5 campos (ej: '0 9 * * 1' = lunes 9am, '0 8 * * 1-5' = lun-vie 8am)"
  - name: recipients
    desc: "lista de destinatarios: usuario Metabase {'type': 'notification-recipient/user', 'user_id': N} o email externo {'type': 'notification-recipient/raw-value', 'details': {'email': 'x@y.com'}}"
  - name: send_condition
    desc: "condicion que dispara el envio: 'has_result' (tiene filas), 'goal_above' (supera goal), 'goal_below' (cae bajo goal)"
  - name: send_once
    desc: "si True, se envia una sola vez y se desactiva automaticamente"
output: "dict: notificacion creada con id, active, payload_type, payload, subscriptions, handlers, created_at"
tested: false
tests: []
test_file_path: ""
file_path: "python/functions/metabase/notifications.py"
---

## Ejemplo

```python
# Alerta: enviar email los lunes 9am si la card tiene resultados
alert = metabase_create_card_alert(
    client,
    card_id=7711,
    cron_schedule="0 9 * * 1",
    recipients=[
        {"type": "notification-recipient/user", "user_id": 1},
        {"type": "notification-recipient/raw-value", "details": {"email": "team@aurgi.com"}},
    ],
    send_condition="has_result",
)
print(alert["id"], alert["active"])
```

## Notas

Requiere Metabase 0.57+. Reemplaza el antiguo /api/pulse.
El campo `subscriptions` acepta solo el tipo `notification-subscription/cron`.
Para alertas de goal configurar previamente el goal en la visualizacion de la card.
`send_once=True` es util para alertas puntuales que no deben repetirse.
