# Avisos por correo y Novedades

`GET /v1/notices`

Los **avisos de tus números y de tus altas** —un número desconectado o quitado, que se conecta y desconecta, bloqueado por Meta o sin tarjeta, envíos rechazados, una plantilla aprobada o bloqueada, el webhook que falla, el historial por vencer, un número conectado, cerca de los 1.000 mensajes gratis, una caída del uso, la ficha del alta de tu cliente— **siempre** quedan en **Novedades** (en el panel y por API). Vos elegís si además llegan por correo.

**El interruptor de la cuenta.** `GET /v1/account/settings` y `PATCH /v1/account/settings` con `{"emailNotices": false}`. Por defecto, `true`.

**La excepción de cada número.** `PATCH /v1/connections/{id}` con `emailNotices`: `inherit` (lo que diga la cuenta, por defecto), `on` u `off`. Cada número trae `emailNotices` y `emailNoticesEffective` (si hoy sus avisos salen por correo). Un aviso de un número sale por correo si el número dice `on`, o dice `inherit` y la cuenta tiene `emailNotices: true`; uno que no es de un número sigue a la cuenta.

**Leerlos.** `GET /v1/notices` (el más nuevo primero; `connectionId`, `unread=true`, `limit` de 1 a 100, `before` = el `nextBefore` de la página anterior, `lang`). Cada aviso trae el mismo texto que el correo (`subject`, `heading`, `paragraphs`, qué hacer, botón) y `emailStatus`: `suppressed_by_preference` = no salió por tu interruptor. `POST /v1/notices/{id}/read` lo marca leído, también en el panel; `POST /v1/notices/read-all` marca todos de una vez (devuelve `updated`, cuántos marcó).

**En el panel.** **Ajustes › Notificaciones** (cuenta y número por número) y la bandeja **Novedades**. Cada correo de estos avisos trae al pie «¿No querés estos correos? Configurá tus avisos».

## Ejemplos

### cURL

```bash
# 1) stop emailing the notices about your numbers (they stay in /v1/notices)
curl -X PATCH https://api.waiaconnect.com/v1/account/settings -H "Authorization: Bearer wc_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" -d '{"emailNotices": false}'
# → { "settings": { "emailNotices": false } }

# 2) …but keep emailing this one number (inherit | on | off)
curl -X PATCH https://api.waiaconnect.com/v1/connections/conn_73dc… -H "Authorization: Bearer wc_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" -d '{"emailNotices": "on"}'

# 3) read the unread notices, in your language
curl "https://api.waiaconnect.com/v1/notices?unread=true&lang=en" -H "Authorization: Bearer wc_live_YOUR_API_KEY"
# → { "notices": [ { "id": 1234, "type": "connection_disconnected", "connectionId": "conn_73dc…",
#       "emailStatus": "suppressed_by_preference", "subject": "…", "paragraphs": ["…"], "cta": { … } } ],
#     "unreadCount": 1, "nextBefore": null }

# 4) mark one as read (idempotent)
curl -X POST https://api.waiaconnect.com/v1/notices/1234/read -H "Authorization: Bearer wc_live_YOUR_API_KEY"

# 5) …or mark them all as read at once
curl -X POST https://api.waiaconnect.com/v1/notices/read-all -H "Authorization: Bearer wc_live_YOUR_API_KEY"
# → { "updated": 3 }
```

### Node.js

```javascript
const H = { "Authorization": "Bearer wc_live_YOUR_API_KEY", "Content-Type": "application/json" };

// the account switch, and one number that keeps emailing
await fetch("https://api.waiaconnect.com/v1/account/settings", { method: "PATCH", headers: H, body: JSON.stringify({ emailNotices: false }) });
await fetch("https://api.waiaconnect.com/v1/connections/conn_73dc…", { method: "PATCH", headers: H, body: JSON.stringify({ emailNotices: "on" }) });

// the unread notices, newest first
const { notices, unreadCount } = await (await fetch("https://api.waiaconnect.com/v1/notices?unread=true&lang=en", { headers: H })).json();
for (const n of notices) {
  console.log(n.type, n.connectionId, n.subject);
  await fetch(`https://api.waiaconnect.com/v1/notices/${n.id}/read`, { method: "POST", headers: H });
}
```

### PHP

```php
<?php
$h = ["Authorization: Bearer wc_live_YOUR_API_KEY", "Content-Type: application/json"];
$ch = curl_init("https://api.waiaconnect.com/v1/account/settings");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_HTTPHEADER => $h,
  CURLOPT_POSTFIELDS => json_encode(["emailNotices" => false]),
]);
curl_exec($ch);

$ch = curl_init("https://api.waiaconnect.com/v1/notices?unread=true&lang=en");
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $h]);
$notices = json_decode(curl_exec($ch), true)["notices"];
foreach ($notices as $n) {
  echo $n["type"] . " " . $n["subject"] . "\n";
  $r = curl_init("https://api.waiaconnect.com/v1/notices/" . $n["id"] . "/read");
  curl_setopt_array($r, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => $h]);
  curl_exec($r);
}
```

### Python

```python
import requests
H = {"Authorization": "Bearer wc_live_YOUR_API_KEY"}

# the account switch, and one number that keeps emailing
requests.patch("https://api.waiaconnect.com/v1/account/settings", headers=H, json={"emailNotices": False})
requests.patch("https://api.waiaconnect.com/v1/connections/conn_73dc…", headers=H, json={"emailNotices": "on"})

# the unread notices, newest first
page = requests.get("https://api.waiaconnect.com/v1/notices", headers=H, params={"unread": "true", "lang": "en"}).json()
for n in page["notices"]:
    print(n["type"], n["connectionId"], n["subject"])
    requests.post(f"https://api.waiaconnect.com/v1/notices/{n['id']}/read", headers=H)
```

## Notas

- **Siempre llegan por correo**, digan lo que digan los interruptores: facturación y pagos, seguridad y acceso, avisos legales, respuestas de soporte y la bienvenida.
- `emailNotices` de la cuenta que no sea `true`/`false` da `400 SETTINGS_INVALID`; el de un número que no sea `inherit`, `on` u `off`, `400 CONNECTION_EMAIL_NOTICES_INVALID`.
- Un parámetro inválido de `GET /v1/notices` da `400 NOTICES_QUERY_INVALID`; un `connectionId` de otra cuenta, `404 CONNECTION_NOT_FOUND`; un aviso de otra cuenta, `404 NOTICE_NOT_FOUND`.
- `type` es un texto abierto (`connection_disconnected`, `template_first_approved`…): se suman tipos nuevos.
