{"openapi":"3.1.0","info":{"title":"WAQR API","version":"1","description":"API pública de WAQR: conexiones de WhatsApp (QR y oficial de Meta), mensajes, conversaciones, contactos, grupos, plantillas, webhooks y, para revendedores, la gestión de sus clientes.\n\n**Autenticación.** Todas las rutas usan `Authorization: Bearer …`:\n- *API key* (`wq_live_…`), creada en el panel (Desarrolladores). Cada ruta exige los scopes que indica; una clave nunca puede más que el usuario que la creó. Nunca envíes la clave en la URL (`400`).\n- *Token de partner*: los revendedores obtienen un token de 10 minutos con `POST /v1/oauth/token` (client credentials).\n\n**Errores.** Formato `application/problem+json` (RFC 9457) con `code` estable (ver el esquema `Problem`), `requestId` y, en validación, `errors[]`.\n\n**Idempotencia.** Las operaciones que crean o cambian aceptan `Idempotency-Key`; las que la marcan como obligatoria la exigen (`400 idempotency_key_required`).\n\n**Respuestas.** Cada operación documenta su cuerpo (ver `components.schemas`). Se pueden añadir campos nuevos sin cambiar de versión: ignora los que no conozcas.\n\n**Paginación.** Por cursor: `?cursor=` con el `nextCursor` de la página anterior (las listas devuelven `{ data, nextCursor }`; `nextCursor` es null en la última página).\n\n**Límites.** `429` con `Retry-After` al superar el límite por clave o por recurso.\n\n**Webhooks.** Eventos firmados con Standard Webhooks (`webhook-id`, `webhook-timestamp`, `webhook-signature`); cuerpo `{ type, timestamp, data }`. Ver la sección `webhooks`."},"servers":[{"url":"https://api.waqr.app"}],"tags":[{"name":"agent"},{"name":"analytics"},{"name":"connections"},{"name":"contacts"},{"name":"conversation-labels"},{"name":"conversations"},{"name":"embed-sessions"},{"name":"groups"},{"name":"integrations"},{"name":"leads"},{"name":"media"},{"name":"messages"},{"name":"partner"},{"name":"partner-api"},{"name":"search"},{"name":"webhooks"}],"paths":{"/v1/agent/catalog":{"put":{"operationId":"put_agent_catalog","tags":["agent"],"summary":"Reemplazar el catálogo de productos del agente de IA","description":"Scopes: `catalog:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"connectionId":{"type":"string","maxLength":64},"source":{"type":"string","enum":["panel","api","wordpress","woocommerce"]},"items":{"maxItems":500,"type":"array","items":{"type":"object","properties":{"externalId":{"type":"string","minLength":1,"maxLength":120},"name":{"type":"string","minLength":1,"maxLength":300},"price":{"anyOf":[{"anyOf":[{"type":"number","minimum":0,"maximum":1000000000},{"type":"string","pattern":"^\\d{1,9}([.,]\\d{1,2})?$"}]},{"type":"null"}]},"currency":{"anyOf":[{"type":"string","pattern":"^[A-Za-z]{3}$"},{"type":"null"}]},"url":{"anyOf":[{"type":"string","maxLength":2000,"format":"uri"},{"type":"null"}]},"stock":{"anyOf":[{"type":"integer","minimum":-1000000,"maximum":100000000},{"type":"null"}]},"sku":{"anyOf":[{"type":"string","maxLength":120},{"type":"null"}]},"description":{"anyOf":[{"type":"string","maxLength":4000},{"type":"null"}]},"image":{"anyOf":[{"type":"string","maxLength":2000,"format":"uri"},{"type":"null"}]}},"required":["externalId","name"]}},"replace":{"default":false,"type":"boolean"},"remove":{"maxItems":500,"type":"array","items":{"type":"string","minLength":1,"maxLength":120}}},"required":["items"]}}}},"security":[{"apiKey":["catalog:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"upserted":{"type":"integer","description":"Productos creados o actualizados."},"removed":{"type":"integer","description":"Productos borrados (`remove` o `replace`)."}},"required":["upserted","removed"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/analytics/waba":{"get":{"operationId":"get_analytics_waba","tags":["analytics"],"summary":"KPIs y costo estimado de WhatsApp oficial","description":"KPIs de WhatsApp oficial y costo estimado con las tarifas de Meta. Permiso `analytics.read`; solo conexiones `waba` (una QR → `409 not_supported_for_engine`). 04-12-2026: también con API key (`usage:read`), para que el CRM de un cliente vea el consumo de sus números oficiales sin entrar al panel.\n\nScopes: `usage:read`.","parameters":[{"name":"range","in":"query","required":false,"schema":{"type":"string","enum":["7","30","90"]}},{"name":"from","in":"query","required":false,"schema":{"type":"string","maxLength":40}},{"name":"to","in":"query","required":false,"schema":{"type":"string","maxLength":40}},{"name":"connection","in":"query","required":false,"schema":{"type":"string","maxLength":64}},{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","maxLength":64}}],"security":[{"apiKey":["usage:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WabaAnalytics"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections":{"get":{"operationId":"get_connections","tags":["connections"],"summary":"Listar conexiones","description":"Scopes: `connections:read`.","security":[{"apiKey":["connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}}},"required":["connections"]},"example":{"connections":[{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_connections","tags":["connections"],"summary":"Crear una conexión","description":"Con API key exige `Idempotency-Key`; con la sesión del dashboard es opcional.\n\nScopes: `connections:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"label":{"type":"string","minLength":1,"maxLength":60}},"required":["label"]}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}":{"delete":{"operationId":"delete_connections_by_id","tags":["connections"],"summary":"Eliminar una conexión","description":"Scopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_connections_by_id","tags":["connections"],"summary":"Ver una conexión","description":"Scopes: `connections:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_connections_by_id","tags":["connections"],"summary":"Cambiar el nombre u otros datos de una conexión","description":"Scopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"label":{"type":"string","minLength":1,"maxLength":60},"groupChatsEnabled":{"type":"boolean"}}}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/groups/sync":{"post":{"operationId":"post_connections_by_id_groups_sync","tags":["connections"],"summary":"Sincronizar todos los grupos del número","description":"Da de alta o actualiza en WAQR todos los grupos del número, con sus participantes, sin esperar a que tengan actividad → `200 { groups, created, updated }`. 1 vez cada 10 min por conexión (`429` con `Retry-After`). También corre sola al conectar el número.\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"groups":{"type":"integer"},"created":{"type":"integer"},"updated":{"type":"integer"}},"required":["groups","created","updated"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/logout":{"post":{"operationId":"post_connections_by_id_logout","tags":["connections"],"summary":"Cerrar la sesión de WhatsApp de una conexión QR","description":"Scopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/qr":{"get":{"operationId":"get_connections_by_id_qr","tags":["connections"],"summary":"Código QR para vincular una conexión","description":"Scopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConnectionQr"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/templates":{"get":{"operationId":"get_connections_by_id_templates","tags":["connections"],"summary":"Listar plantillas (con variables y vista previa)","description":"Plantillas de una conexión de WhatsApp oficial. → `{ templates: [{ name, language, category, status, parameterFormat, rejectedReason, components, createdAt, updatedAt }] }`. En una conexión QR → `409 not_supported_for_engine`.\n\nScopes: `connections:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"templates":{"type":"array","items":{"$ref":"#/components/schemas/Template"}}},"required":["templates"]},"example":{"templates":[{"name":"confirmacion_pedido","language":"es","category":"UTILITY","status":"APPROVED","parameterFormat":"POSITIONAL","rejectedReason":null,"components":[{"type":"HEADER","format":"IMAGE"},{"type":"BODY","text":"Hola {{1}}, tu pedido {{2}} está confirmado."},{"type":"FOOTER","text":"Tienda Ejemplo"}],"previousCategory":null,"categoryChangedAt":null,"statusChangedAt":"2026-11-28T12:00:00.000Z","createdAt":"2026-11-28T11:58:00.000Z","updatedAt":"2026-11-28T12:00:00.000Z","headerFormat":"IMAGE","variables":{"header":[],"body":["1","2"],"buttons":[]},"preview":{"header":"[imagen]","body":"Hola {{1}}, tu pedido {{2}} está confirmado.","footer":"Tienda Ejemplo"},"headerDefault":{"mimeType":"image/jpeg","fileName":"pedido.jpg","sizeBytes":48213,"setAt":"2026-11-28T12:05:00.000Z"}}]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_connections_by_id_templates","tags":["connections"],"summary":"Crear una plantilla en Meta","description":"Crea una plantilla (validada como Meta; en Meta `POST /{wabaId}/message_templates`, en la demo solo en local) → `201 { template }`. Límite `wabaTemplateCreate` 20/h por conexión. Errores: `422 validation_failed` (reglas), `409 waba_template_exists`, `422 waba_template_invalid` (Meta), `502 waba_meta_unavailable`, `409 waba_token_invalid`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":600},"language":{"type":"string","minLength":2,"maxLength":12},"category":{"type":"string","enum":["MARKETING","UTILITY","AUTHENTICATION"]},"header":{"type":"object","properties":{"format":{"type":"string","enum":["TEXT","IMAGE","DOCUMENT","VIDEO"]},"text":{"type":"string","maxLength":4096},"example":{"type":"string","maxLength":4096}},"required":["format"],"additionalProperties":false},"body":{"type":"object","properties":{"text":{"type":"string","maxLength":8192},"examples":{"anyOf":[{"maxItems":100,"type":"array","items":{"type":"string","maxLength":4096}},{"type":"object","propertyNames":{"type":"string","maxLength":100},"additionalProperties":{"type":"string","maxLength":4096}}]}},"required":["text"],"additionalProperties":false},"footer":{"type":"string","maxLength":4096},"buttons":{"maxItems":20,"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["QUICK_REPLY","URL","PHONE_NUMBER"]},"text":{"type":"string","maxLength":4096},"url":{"type":"string","maxLength":4096},"phoneNumber":{"type":"string","maxLength":64},"example":{"type":"string","maxLength":4096}},"required":["type","text"],"additionalProperties":false}},"authentication":{"type":"object","properties":{"addSecurityRecommendation":{"type":"boolean"},"codeExpirationMinutes":{"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},"buttonText":{"type":"string","maxLength":4096}},"additionalProperties":false}},"required":["name","language","category"],"additionalProperties":false}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"template":{"$ref":"#/components/schemas/Template"}},"required":["template"]},"example":{"template":{"name":"confirmacion_pedido","language":"es","category":"UTILITY","status":"APPROVED","parameterFormat":"POSITIONAL","rejectedReason":null,"components":[{"type":"HEADER","format":"IMAGE"},{"type":"BODY","text":"Hola {{1}}, tu pedido {{2}} está confirmado."},{"type":"FOOTER","text":"Tienda Ejemplo"}],"previousCategory":null,"categoryChangedAt":null,"statusChangedAt":"2026-11-28T12:00:00.000Z","createdAt":"2026-11-28T11:58:00.000Z","updatedAt":"2026-11-28T12:00:00.000Z","headerFormat":"IMAGE","variables":{"header":[],"body":["1","2"],"buttons":[]},"preview":{"header":"[imagen]","body":"Hola {{1}}, tu pedido {{2}} está confirmado.","footer":"Tienda Ejemplo"},"headerDefault":{"mimeType":"image/jpeg","fileName":"pedido.jpg","sizeBytes":48213,"setAt":"2026-11-28T12:05:00.000Z"}}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/templates/{name}":{"delete":{"operationId":"delete_connections_by_id_templates_by_name","tags":["connections"],"summary":"Eliminar una plantilla","description":"Elimina una plantilla → `204`. Sin `?language=` borra todos los idiomas con ese nombre (así lo hace Meta); con idioma, solo ese. `404 waba_template_not_found` si no existe en WAQR.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"name","in":"path","required":true,"schema":{"type":"string"},"description":"Nombre de la plantilla de WhatsApp."},{"name":"language","in":"query","required":false,"schema":{"type":"string","minLength":2,"maxLength":12}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/templates/{name}/header-default":{"put":{"operationId":"put_connections_by_id_templates_by_name_header_default","tags":["connections"],"summary":"Fijar o quitar el archivo de cabecera predeterminado de una plantilla","description":"Archivo de cabecera predeterminado de una plantilla de cabecera imagen, video o documento. Un envío de esa plantilla sin cabecera propia lo usa (WAQR lo sube a Meta). `{ uploadId: null }` lo quita → `200 { templates }`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"name","in":"path","required":true,"schema":{"type":"string"},"description":"Nombre de la plantilla de WhatsApp."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"uploadId":{"anyOf":[{"type":"string","minLength":3,"maxLength":80},{"type":"null"}]},"language":{"type":"string","minLength":2,"maxLength":12}},"required":["uploadId"],"additionalProperties":false}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"templates":{"type":"array","items":{"$ref":"#/components/schemas/Template"}}},"required":["templates"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/templates/stats":{"delete":{"operationId":"delete_connections_by_id_templates_stats","tags":["connections"],"summary":"Eliminar la plantilla llamada «stats»","description":"Una plantilla que se llama «stats» (nombre válido en Meta): mismo `DELETE` que `templates/{name}`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"language","in":"query","required":false,"schema":{"type":"string","minLength":2,"maxLength":12}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_connections_by_id_templates_stats","tags":["connections"],"summary":"Estadísticas de envío por plantilla","description":"Estadísticas de plantillas calculadas con los mensajes de WAQR → `{ range, totals, byTemplate, contacts: { total, nextCursor, data }, sends: { total, nextCursor, data }, truncated }`.\n\nScopes: `connections:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"from","in":"query","required":false,"schema":{"type":"string","maxLength":40}},{"name":"to","in":"query","required":false,"schema":{"type":"string","maxLength":40}},{"name":"template","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}},{"name":"response","in":"query","required":false,"schema":{"type":"string","enum":["replied","replied_24h","replied_7d","replied_later","no_reply","clicked"]}},{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["pending","sent","delivered","read","failed"]}},{"name":"window","in":"query","required":false,"schema":{"type":"string","enum":["open","closed"]}},{"name":"q","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":120}},{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}},{"name":"contactsCursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"sendsCursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":200}}],"security":[{"apiKey":["connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateStats"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/templates/sync":{"delete":{"operationId":"delete_connections_by_id_templates_sync","tags":["connections"],"summary":"Eliminar la plantilla llamada «sync»","description":"Una plantilla que se llama «sync» (nombre válido en Meta): mismo `DELETE` que `templates/{name}`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"language","in":"query","required":false,"schema":{"type":"string","minLength":2,"maxLength":12}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_connections_by_id_templates_sync","tags":["connections"],"summary":"Refrescar las plantillas desde Meta","description":"Vuelve a leer las plantillas de Meta (límite `wabaTemplateSync` 6/h por conexión; en la demo, local). → `{ templates: [...], syncedAt }` · `409 not_supported_for_engine` en una conexión QR · `409 waba_token_invalid` si Meta revocó el acceso.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"templates":{"type":"array","items":{"$ref":"#/components/schemas/Template"}},"syncedAt":{"type":"string","format":"date-time"}},"required":["templates","syncedAt"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/waba/refresh":{"post":{"operationId":"post_connections_by_id_waba_refresh","tags":["connections"],"summary":"Refrescar estado, calidad y salud de la cuenta oficial","description":"«Refrescar estado» de una conexión de WhatsApp oficial: relee de Meta el número y la cuenta y actualiza `lastSyncAt` (en la demo, local) → `{ connection }`. Límite `wabaRefresh` 6/h por conexión (demo: 60/h). Errores: `409 not_supported_for_engine` (QR), `409 waba_token_invalid`, `502 waba_meta_unavailable`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/waba/usage":{"get":{"operationId":"get_connections_by_id_waba_usage","tags":["connections"],"summary":"Consumo mensual de WhatsApp oficial","description":"Consumo del mes (UTC) de una conexión de WhatsApp oficial: `{ connectionId, month, sentMessages, billableMessages, pricedMessages, estimatedTotalUsd, byCategory, alert, disclaimer }`. `?month=AAAA-MM` (por defecto, el actual). `billableMessages` = los que Meta marcó como cobrados; el costo es una estimación con las tarifas públicas.\n\nScopes: `usage:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"month","in":"query","required":false,"schema":{"type":"string","pattern":"^\\d{4}-(0[1-9]|1[0-2])$"}}],"security":[{"apiKey":["usage:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WabaUsage"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/waba/usage-alert":{"put":{"operationId":"put_connections_by_id_waba_usage_alert","tags":["connections"],"summary":"Fijar el tope mensual de consumo","description":"Tope mensual de consumo de una conexión de WhatsApp oficial: `{ monthlyBillable?, monthlyCostUsd? }` (null quita ese tope; los dos null, ninguno). Al pasarlo, el webhook `connection.usage_threshold_reached` (una vez por tope y mes) → `{ connectionId, alert }`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"monthlyBillable":{"anyOf":[{"type":"integer","exclusiveMinimum":0,"maximum":100000000},{"type":"null"}]},"monthlyCostUsd":{"anyOf":[{"type":"number","exclusiveMinimum":0,"maximum":10000000},{"type":"null"}]}},"additionalProperties":false}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"alert":{"anyOf":[{"type":"object","properties":{"monthlyBillable":{"anyOf":[{"type":"integer"},{"type":"null"}]},"monthlyCostUsd":{"type":["number","null"]}},"required":["monthlyBillable","monthlyCostUsd"]},{"type":"null"}]}},"required":["connectionId","alert"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/welcome":{"get":{"operationId":"get_connections_by_id_welcome","tags":["connections"],"summary":"Ver la bienvenida de leads de una conexión","description":"Bienvenida de los leads web de una conexión → `{ enabled, dailyCap, dedupeDays, variants: { default, form, product, page: { text, template } }, followUp: { enabled, afterHours, text, template }, engine }`. Sin configurar, los valores por defecto.\n\nScopes: `connections:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WelcomeSettings"}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_connections_by_id_welcome","tags":["connections"],"summary":"Cambiar la bienvenida de leads de una conexión","description":"Cambio parcial (lo que no llega se conserva; `template: null` la quita). `connections.manage`.\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"type":"boolean"},"dailyCap":{"type":"integer","minimum":1,"maximum":1000},"dedupeDays":{"type":"integer","minimum":1,"maximum":90},"variants":{"type":"object","properties":{"default":{"type":"object","properties":{"text":{"type":"string","maxLength":1000},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"params":{"default":[],"maxItems":10,"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"]}}},"required":["name","language"],"additionalProperties":false},{"type":"null"}]}},"additionalProperties":false},"form":{"type":"object","properties":{"text":{"type":"string","maxLength":1000},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"params":{"default":[],"maxItems":10,"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"]}}},"required":["name","language"],"additionalProperties":false},{"type":"null"}]}},"additionalProperties":false},"product":{"type":"object","properties":{"text":{"type":"string","maxLength":1000},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"params":{"default":[],"maxItems":10,"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"]}}},"required":["name","language"],"additionalProperties":false},{"type":"null"}]}},"additionalProperties":false},"page":{"type":"object","properties":{"text":{"type":"string","maxLength":1000},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"params":{"default":[],"maxItems":10,"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"]}}},"required":["name","language"],"additionalProperties":false},{"type":"null"}]}},"additionalProperties":false}},"additionalProperties":false},"followUp":{"type":"object","properties":{"enabled":{"type":"boolean"},"afterHours":{"type":"integer","minimum":1,"maximum":168},"text":{"type":"string","maxLength":1000},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"params":{"default":[],"maxItems":10,"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"]}}},"required":["name","language"],"additionalProperties":false},{"type":"null"}]}},"additionalProperties":false},"engine":{"type":"string","maxLength":20}},"additionalProperties":false}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WelcomeSettings"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/{id}/welcome/suggested-template":{"post":{"operationId":"post_connections_by_id_welcome_suggested_template","tags":["connections"],"summary":"Crear la plantilla de bienvenida sugerida","description":"`{ variant }` (`default` · `form` · `product` · `page` · `followUp`) → crea en Meta, con el flujo de plantillas existente, la plantilla UTILITY sugerida con el texto por defecto de la variante y la asocia → `201 { template: { name, language, status } }`. Si ya existía con ese nombre, la asocia sin crear otra. Solo WhatsApp oficial (QR → `409 not_supported_for_engine`).\n\nScopes: `connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"variant":{"type":"string","enum":["default","form","product","page","followUp"]}},"required":["variant"],"additionalProperties":false}}}},"security":[{"apiKey":["connections:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"template":{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"status":{"type":"string","description":"Estado en Meta: `PENDING` hasta que la aprueben, `APPROVED`…"},"params":{"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"],"description":"Variable del lead que va en ese parámetro de la plantilla."}}},"required":["name","language","status","params"]}},"required":["template"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/connections/quota":{"get":{"operationId":"get_connections_quota","tags":["connections"],"summary":"Cupo de conexiones de la organización","description":"Scopes: `connections:read`.","security":[{"apiKey":["connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConnectionQuota"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts":{"get":{"operationId":"get_contacts","tags":["contacts"],"summary":"Listar y buscar contactos","description":"Contactos: `?q=&createdVia=group_message&cursor=&limit=`.\n\nScopes: `contacts:read`.","parameters":[{"name":"q","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":120}},{"name":"createdVia","in":"query","required":false,"schema":{"type":"string","enum":["inbound_message","group_message","group_participant","group","outbound_message","manual","google","api","import"]}},{"name":"phone","in":"query","required":false,"schema":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}},{"name":"userId","in":"query","required":false,"schema":{"type":"string","minLength":3,"maxLength":140}},{"name":"username","in":"query","required":false,"schema":{"type":"string"}},{"name":"limit","in":"query","required":false,"schema":{"default":30,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["contacts:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Contact"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]},"example":{"data":[{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"givenName":null,"familyName":null,"company":null,"notes":null,"createdVia":"inbound_message","lastInteractionAt":"2026-12-01T10:15:00.000Z","userEditedAt":null,"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z","avatar":null}],"nextCursor":null}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/{id}":{"get":{"operationId":"get_contacts_by_id","tags":["contacts"],"summary":"Ver la ficha de un contacto","description":"Ficha: identidades, nombres observados con su fuente, conversaciones y grupos.\n\nScopes: `contacts:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["contacts:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"contact":{"$ref":"#/components/schemas/ContactDetail"}},"required":["contact"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_contacts_by_id","tags":["contacts"],"summary":"Editar un contacto (nombre, datos, teléfono declarado)","description":"Edita el nombre visible y los datos propios del contacto (cambio parcial; `null` borra un campo). `phoneE164` guarda el teléfono declarado de un contacto que escribe sin número (solo con su id de usuario de WhatsApp): después, un envío por ese número cae en el mismo contacto y la misma conversación. Si el número ya es el WhatsApp de otro contacto → `409 contact_phone_conflict` con su `contactId`.\n\nScopes: `contacts:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"displayName":{"anyOf":[{"type":"string","minLength":1,"maxLength":128},{"type":"null"}]},"givenName":{"anyOf":[{"type":"string","maxLength":80},{"type":"null"}]},"familyName":{"anyOf":[{"type":"string","maxLength":80},{"type":"null"}]},"company":{"anyOf":[{"type":"string","maxLength":120},{"type":"null"}]},"notes":{"anyOf":[{"type":"string","maxLength":4000},{"type":"null"}]},"phoneE164":{"anyOf":[{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"},{"type":"null"}]}},"additionalProperties":false}}}},"security":[{"apiKey":["contacts:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"contact":{"$ref":"#/components/schemas/ContactDetail"}},"required":["contact"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/{id}/avatar":{"get":{"operationId":"get_contacts_by_id_avatar","tags":["contacts"],"summary":"Foto de perfil de un contacto","description":"Foto de perfil del contacto: el binario (`image/jpeg|png|webp`) con caché privada de 1 h y ETag (`If-None-Match` → 304). 404 si no tiene foto o no es visible para el miembro.\n\nScopes: `contacts:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["contacts:read"]}],"responses":{"200":{"description":"OK. La imagen (`image/jpeg`, `image/png` o `image/webp`). Admite `If-None-Match` (304).","content":{"image/*":{"schema":{"type":"string","contentMediaType":"image/*"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/{id}/block":{"post":{"operationId":"post_contacts_by_id_block","tags":["contacts"],"summary":"Bloquear un contacto en WhatsApp","description":"Block del contacto en WhatsApp y en WAQR; owner o admin.\n\nScopes: `contacts:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["contacts:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"contactId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"blocked":{"type":"boolean"},"blockedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["contactId","blocked","blockedAt"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/{id}/merge":{"post":{"operationId":"post_contacts_by_id_merge","tags":["contacts"],"summary":"Fusionar dos contactos","description":"Fusión manual: el contacto de la ruta sobrevive y absorbe `contactId` (identidades, nombres, puntos, conversaciones, participaciones y vínculos). Reversible con `POST …/{contactId}/unmerge`.\n\nScopes: `contacts:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"contactId":{"type":"string","minLength":5,"maxLength":64}},"required":["contactId"],"additionalProperties":false}}}},"security":[{"apiKey":["contacts:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"merge":{"type":"object","properties":{"id":{"type":"string","pattern":"^cmg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`cmg_…`)."},"survivorId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"mergedId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"reason":{"type":"string","const":"manual"},"createdAt":{"type":"string","format":"date-time"}},"required":["id","survivorId","mergedId","reason","createdAt"]},"contact":{"$ref":"#/components/schemas/ContactDetail"}},"required":["merge","contact"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/{id}/unblock":{"post":{"operationId":"post_contacts_by_id_unblock","tags":["contacts"],"summary":"Desbloquear un contacto en WhatsApp","description":"Unblock del contacto en WhatsApp y en WAQR; owner o admin.\n\nScopes: `contacts:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["contacts:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"contactId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"blocked":{"type":"boolean"},"blockedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["contactId","blocked","blockedAt"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/{id}/unmerge":{"post":{"operationId":"post_contacts_by_id_unmerge","tags":["contacts"],"summary":"Deshacer una fusión de contactos","description":"Revierte la fusión manual que absorbió al contacto de la ruta (el que desapareció). Cuerpo `{}` o `{ mergeId: 'cmg_…' }`. Una fusión automática por par PN↔LID → `409 merge_not_reversible`.\n\nScopes: `contacts:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"mergeId":{"type":"string","minLength":5,"maxLength":64}},"additionalProperties":false}}}},"security":[{"apiKey":["contacts:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"merge":{"type":"object","properties":{"id":{"type":"string","pattern":"^cmg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`cmg_…`)."},"survivorId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"restoredId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"revertedAt":{"type":"string","format":"date-time"}},"required":["id","survivorId","restoredId","revertedAt"]},"contact":{"$ref":"#/components/schemas/ContactDetail"}},"required":["merge","contact"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/conflicts":{"get":{"operationId":"get_contacts_conflicts","tags":["contacts"],"summary":"Conflictos de sincronización con Google Contacts","description":"Conflictos de sincronización con Google Contacts (`?status=open|resolved&cursor=&limit=`).\n\nScopes: `contacts:read`.","parameters":[{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["open","resolved"]}},{"name":"limit","in":"query","required":false,"schema":{"default":30,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["contacts:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/SyncConflict"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/contacts/conflicts/{id}/resolve":{"post":{"operationId":"post_contacts_conflicts_by_id_resolve","tags":["contacts"],"summary":"Resolver un conflicto de sincronización","description":"Resolver un conflicto: `local`, `remote` o `custom` (con `value`).\n\nScopes: `contacts:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"resolution":{"type":"string","enum":["local","remote","custom"]},"value":{"anyOf":[{"type":"string","maxLength":4000},{"type":"null"}]}},"required":["resolution"],"additionalProperties":false}}}},"security":[{"apiKey":["contacts:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conflict":{"type":"object","properties":{"id":{"type":"string","pattern":"^csc_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`csc_…`)."},"field":{"type":"string","enum":["name","company","notes"]},"resolution":{"type":"string","enum":["local","remote","custom"]},"contactId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."}},"required":["id","field","resolution","contactId"]}},"required":["conflict"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversation-labels":{"get":{"operationId":"get_conversation_labels","tags":["conversation-labels"],"summary":"Listar etiquetas de conversación","description":"Etiquetas de conversaciones de la organización (`inbox.read`).\n\nScopes: `conversations:read`.","security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ConversationLabel"}}},"required":["data"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations":{"get":{"operationId":"get_conversations","tags":["conversations"],"summary":"Listar conversaciones","description":"Bandeja: `?connectionId=&kind=direct|group&status=&unread=&cursor=&limit=` y `pinned=`, `assigned=me|none|usr_…` y `label=lbl_…`. Las favoritas van primero.\n\nScopes: `conversations:read`.","parameters":[{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"kind","in":"query","required":false,"schema":{"type":"string","enum":["direct","group"]}},{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["open","closed","archived"]}},{"name":"unread","in":"query","required":false,"schema":{"type":"string","enum":["0","1","true","false"]}},{"name":"pinned","in":"query","required":false,"schema":{"type":"string","enum":["0","1","true","false"]}},{"name":"assigned","in":"query","required":false,"schema":{"anyOf":[{"type":"string","enum":["me","none"]},{"type":"string","minLength":5,"maxLength":64}]}},{"name":"label","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"limit","in":"query","required":false,"schema":{"default":30,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Conversation"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]},"example":{"data":[{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}],"nextCursor":null}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}":{"get":{"operationId":"get_conversations_by_id","tags":["conversations"],"summary":"Ver una conversación","description":"La conversación lleva `lead` = el último lead del contacto en esa conexión (`{ id, variant, page, product, form, topic, createdAt }`) o null.\n\nScopes: `conversations:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversation":{"$ref":"#/components/schemas/ConversationDetail"}},"required":["conversation"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_conversations_by_id","tags":["conversations"],"summary":"Cambiar estado, asignación o etiquetas de una conversación","description":"Estado (`open`, `closed`, `archived`) y favorita del equipo (`pinned`), asignación (`assignedUserId`, un miembro que responde chats, o null) y etiquetas (`labelIds`, lista completa); requiere `inbox.reply`. Avisa por tiempo real `conversation.updated`.\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["open","closed","archived"]},"pinned":{"type":"boolean"},"assignedUserId":{"anyOf":[{"type":"string","minLength":5,"maxLength":64},{"type":"null"}]},"labelIds":{"maxItems":20,"type":"array","items":{"type":"string","minLength":5,"maxLength":64}},"mutedUntil":{"anyOf":[{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"},{"type":"string","const":"forever"},{"type":"null"}]}},"additionalProperties":false}}}},"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversation":{"$ref":"#/components/schemas/Conversation"}},"required":["conversation"]},"example":{"conversation":{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/agent":{"put":{"operationId":"put_conversations_by_id_agent","tags":["conversations"],"summary":"Activar o pausar el agente de IA en una conversación","description":"Conmutador «IA activa/pausada» de la bandeja (`inbox.reply`).\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"paused":{"type":"boolean"}},"required":["paused"]}}}},"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"agent":{"$ref":"#/components/schemas/ConversationAgent"}},"required":["agent"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/clear":{"post":{"operationId":"post_conversations_by_id_clear","tags":["conversations"],"summary":"Vaciar los mensajes de una conversación","description":"«Vaciar chat»: oculta en WAQR todos los mensajes actuales (recuperables; no toca el teléfono).\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"hidden":{"type":"integer","description":"Mensajes ocultados."}},"required":["conversationId","hidden"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/export":{"get":{"operationId":"get_conversations_by_id_export","tags":["conversations"],"summary":"Exportar una conversación","description":"Exportar el chat como descarga (`?format=txt|csv`), del más antiguo al más reciente y hasta 10 000 mensajes.\n\nScopes: `messages:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"format","in":"query","required":false,"schema":{"default":"txt","type":"string","enum":["txt","csv"]}}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK. El chat como archivo (`?format=`). `X-Waqr-Truncated: true` si se cortó.","content":{"text/plain":{"schema":{"type":"string"}},"text/csv":{"schema":{"type":"string"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/messages":{"get":{"operationId":"get_conversations_by_id_messages","tags":["conversations"],"summary":"Mensajes de una conversación","description":"Mensajes de la conversación, del más reciente al más antiguo (`?cursor=&limit=`, máx. 100).\n\nScopes: `messages:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}},{"name":"q","in":"query","required":false,"schema":{"type":"string","minLength":2,"maxLength":200}},{"name":"includeHidden","in":"query","required":false,"schema":{"type":"string","enum":["0","1","true","false"]}}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Message"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]},"example":{"data":[{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}],"nextCursor":null}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_conversations_by_id_messages","tags":["conversations"],"summary":"Enviar un mensaje en una conversación","description":"Responder en la conversación con un texto o un adjunto, citando si se quiere (`quotedMessageId`). Se encola y responde 202 con el mensaje `pending`; el estado llega por tiempo real (`message.updated`) y por webhooks (`message.sent` / `message.failed`). `Idempotency-Key` obligatoria.\n\nScopes: `messages:send`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"type":{"default":"text","type":"string","enum":["text","image","video","audio","document","template"]},"template":{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"components":{"description":"Parámetros de la plantilla como en la Cloud API de Meta (`header`, `body`, `button`). En una cabecera de imagen, video o documento, el archivo puede ir por `uploadId` (de `POST /v1/media/uploads`) en lugar de `id`/`link`: `{ \"type\": \"header\", \"parameters\": [{ \"type\": \"document\", \"document\": { \"uploadId\": \"upl_…\", \"filename\": \"Factura.pdf\" } }] }` (`image`/`video` igual, sin `filename`). El tipo debe coincidir con la cabecera de la plantilla; imagen JPEG/PNG ≤ 5 MB, video MP4/3GPP ≤ 16 MB, documento ≤ 100 MB. Sin `header`, se usa el archivo predeterminado de la plantilla si lo tiene.","maxItems":20,"type":"array","items":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{}}}},"required":["name","language"],"additionalProperties":false},"text":{"type":"string"},"uploadId":{"type":"string","minLength":5,"maxLength":64},"caption":{"type":"string","maxLength":4096},"fileName":{"type":"string","minLength":1,"maxLength":255},"quotedMessageId":{"type":"string","minLength":5,"maxLength":64},"mentions":{"maxItems":256,"type":"array","items":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}},"mentionAll":{"type":"boolean"}},"additionalProperties":false}}}},"security":[{"apiKey":["messages:send"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/notes":{"post":{"operationId":"post_conversations_by_id_notes","tags":["conversations"],"summary":"Añadir una nota interna","description":"Nota interna del equipo en la línea de tiempo (`{ text }`); nunca se envía al cliente.\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string","minLength":1,"maxLength":4096}},"required":["text"],"additionalProperties":false}}}},"security":[{"apiKey":["conversations:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/purge":{"post":{"operationId":"post_conversations_by_id_purge","tags":["conversations"],"summary":"Borrar definitivamente una conversación","description":"«Borrar toda la conversación». Borra de verdad, al instante y sin recuperación, los mensajes, adjuntos (y sus objetos del bucket) y la conversación en WAQR; no toca el teléfono. Solo owner/admin (`inbox.messages.manage`) o una API key con `messages:manage`.\n\nScopes: `messages:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["messages:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"purged":{"type":"boolean","const":true},"messagesDeleted":{"type":"integer"},"attachmentsDeleted":{"type":"integer"}},"required":["conversationId","purged","messagesDeleted","attachmentsDeleted"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/read":{"post":{"operationId":"post_conversations_by_id_read","tags":["conversations"],"summary":"Marcar una conversación como leída","description":"Marca la conversación como leída (no se envía confirmación de lectura a WhatsApp).\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversation":{"$ref":"#/components/schemas/Conversation"}},"required":["conversation"]},"example":{"conversation":{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/starred":{"get":{"operationId":"get_conversations_by_id_starred","tags":["conversations"],"summary":"Mensajes destacados de una conversación","description":"Mensajes destacados de este chat (`?limit=&cursor=`).\n\nScopes: `messages:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Message"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]},"example":{"data":[{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}],"nextCursor":null}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/{id}/unread":{"post":{"operationId":"post_conversations_by_id_unread","tags":["conversations"],"summary":"Marcar una conversación como no leída","description":"«Marcar como no leída» (el contador queda en al menos 1; requiere `inbox.reply`).\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversation":{"$ref":"#/components/schemas/Conversation"}},"required":["conversation"]},"example":{"conversation":{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/assignees":{"get":{"operationId":"get_conversations_assignees","tags":["conversations"],"summary":"Personas a las que se puede asignar una conversación","description":"Miembros a los que se puede asignar una conversación (nombre y avatar, sin email).\n\nScopes: `conversations:read`.","security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},"name":{"type":"string"},"role":{"type":"string"},"avatar":{},"me":{"type":"boolean"}},"required":["id","name","role","avatar","me"]}}},"required":["data"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/conversations/counts":{"get":{"operationId":"get_conversations_counts","tags":["conversations"],"summary":"Contadores de la bandeja (sin leer, asignadas…)","description":"Contadores de los chips de la bandeja (`?connectionId=&status=`) → `{ all, unread, groups, pinned, assignedToMe, unassigned, archived, labels: [{ id, count }] }`.\n\nScopes: `conversations:read`.","parameters":[{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["open","closed","archived"]}}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"all":{"type":"integer"},"unread":{"type":"integer"},"groups":{"type":"integer"},"pinned":{"type":"integer"},"assignedToMe":{"type":"integer"},"unassigned":{"type":"integer"},"archived":{"type":"integer"},"labels":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^lbl_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`lbl_…`)."},"count":{"type":"integer"}},"required":["id","count"]}}},"required":["all","unread","groups","pinned","assignedToMe","unassigned","archived","labels"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/embed-sessions":{"post":{"operationId":"post_embed_sessions","tags":["embed-sessions"],"summary":"Código de un uso para embeber «Vincular WhatsApp»","description":"El cliente de un revendedor pide, con su API key `wq_…` (scopes `connections:read` + `connections:write`; también vale la sesión del panel), un código de un uso para embeber SU superficie. `{ surface: 'connections', parentOrigin }` → `201 { code, expiresAt, expiresInSeconds: 60, surface, embedUrl }`. La organización es la de la credencial y el revendedor, su `partnerOrg`: sin revendedor → `409 embed_not_available`. Sin `Idempotency-Key` (código de un uso).\n\nScopes: `connections:read`, `connections:write`.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"surface":{"type":"string","const":"connections"},"parentOrigin":{"type":"string","minLength":1,"maxLength":300},"engines":{"minItems":1,"maxItems":2,"type":"array","items":{"type":"string","enum":["qr","waba"]}}},"required":["surface","parentOrigin"]}}}},"security":[{"apiKey":["connections:read","connections:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"string","description":"Código de un uso para abrir el embebido."},"expiresAt":{"type":"string","format":"date-time"},"expiresInSeconds":{"type":"integer"},"surface":{"type":"string"},"embedUrl":{"type":"string"}},"required":["code","expiresAt","expiresInSeconds","surface","embedUrl"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups":{"get":{"operationId":"get_groups","tags":["groups"],"summary":"Listar grupos","description":"Grupos observados: `?connectionId=&jid=&status=&cursor=&limit=`. `jid` es un filtro exacto por el JID de WhatsApp (`1203…@g.us`).\n\nScopes: `conversations:read`.","parameters":[{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"jid","in":"query","required":false,"schema":{"type":"string","pattern":"^[0-9-]{5,64}@g\\.us$"}},{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["observed","active","left","ignored"]}},{"name":"limit","in":"query","required":false,"schema":{"default":30,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Group"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_groups","tags":["groups"],"summary":"Crear un grupo","description":"Crear un grupo desde una conexión por QR → `201 { group, results, picture, inviteLink }`. La conversación del grupo se crea en el mismo momento. `Idempotency-Key` obligatoria: un reintento con la misma clave y el mismo cuerpo devuelve la misma respuesta y no crea otro grupo. WhatsApp oficial → `422 engine_unsupported`.\n\nScopes: `groups:manage`.","parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"connectionId":{"type":"string","minLength":5,"maxLength":64},"subject":{"type":"string","minLength":1,"maxLength":100},"description":{"type":"string","maxLength":2048},"participants":{"minItems":1,"maxItems":256,"type":"array","items":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}},"admins":{"maxItems":256,"type":"array","items":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}},"pictureUploadId":{"type":"string","minLength":5,"maxLength":64}},"required":["connectionId","subject","participants"],"additionalProperties":false}}}},"security":[{"apiKey":["groups:manage"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"group":{"$ref":"#/components/schemas/GroupDetail"},"results":{"type":"array","items":{"anyOf":[{"type":"object","properties":{"phone":{"type":"string"},"ok":{"type":"boolean","const":true},"admin":{"type":"boolean"}},"required":["phone","ok","admin"]},{"type":"object","properties":{"phone":{"type":"string"},"ok":{"type":"boolean","const":false},"reason":{"type":"string"}},"required":["phone","ok","reason"]}]}},"picture":{"anyOf":[{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]},{"type":"null"}]},"inviteLink":{"description":"Enlace de invitación si alguien no se pudo añadir por su privacidad.","type":["string","null"]}},"required":["group","results","picture","inviteLink"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}":{"get":{"operationId":"get_groups_by_id","tags":["groups"],"summary":"Ver un grupo","description":"Grupo con sus primeros 200 participantes activos (`participantsNextCursor` para el resto). `manage` dice si el miembro puede administrarlo y el rol del número de la conexión en el grupo.\n\nScopes: `conversations:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"group":{"$ref":"#/components/schemas/GroupDetail"}},"required":["group"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_groups_by_id","tags":["groups"],"summary":"Cambiar nombre, descripción o ajustes de un grupo","description":"Cambiar el nombre y/o la descripción del grupo en WhatsApp.\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"subject":{"type":"string","minLength":1,"maxLength":100},"description":{"type":"string","maxLength":2048}},"additionalProperties":false}}}},"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"groupId":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"status":{"type":"string","const":"applied"}},"required":["groupId","status"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/avatar":{"get":{"operationId":"get_groups_by_id_avatar","tags":["groups"],"summary":"Foto de un grupo","description":"Foto del grupo: el binario (`image/jpeg|png|webp`) con caché privada de 1 h y ETag (`If-None-Match` → 304). 404 si no tiene foto o la conexión del grupo está fuera del alcance.\n\nScopes: `conversations:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK. La imagen (`image/jpeg`, `image/png` o `image/webp`). Admite `If-None-Match` (304).","content":{"image/*":{"schema":{"type":"string","contentMediaType":"image/*"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/invite":{"get":{"operationId":"get_groups_by_id_invite","tags":["groups"],"summary":"Enlace de invitación de un grupo","description":"Enlace de invitación vigente del grupo (solo si el número es admin).\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"invite":{"type":"object","properties":{"code":{"type":"string"},"url":{"type":"string"}},"required":["code","url"]}},"required":["invite"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/invite/revoke":{"post":{"operationId":"post_groups_by_id_invite_revoke","tags":["groups"],"summary":"Revocar el enlace de invitación de un grupo","description":"Anula el enlace de invitación y devuelve el nuevo.\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"invite":{"type":"object","properties":{"code":{"type":"string"},"url":{"type":"string"}},"required":["code","url"]}},"required":["invite"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/leave":{"post":{"operationId":"post_groups_by_id_leave","tags":["groups"],"summary":"Salir de un grupo","description":"La conexión sale del grupo (y, con `archive`, se archiva la conversación).\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"archive":{"type":"boolean"}},"additionalProperties":false}}}},"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"groupId":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"status":{"type":"string","const":"left"},"conversationId":{"anyOf":[{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},{"type":"null"}]},"archived":{"type":"boolean"}},"required":["groupId","status","conversationId","archived"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/messages":{"post":{"operationId":"post_groups_by_id_messages","tags":["groups"],"summary":"Enviar un mensaje a un grupo","description":"Escribir a cualquier grupo observado (aparece en `GET /v1/groups`), tenga o no conversación: si no la tiene, se crea con este mensaje. Mismo cuerpo y misma respuesta que `POST /v1/conversations/{id}/messages` (`202 { message }`, con `conversationId`), más las menciones (`mentions`, `mentionAll`). `Idempotency-Key` obligatoria. `409 group_read_only` si el número ya no está en el grupo; `422 connection_offline` si la conexión no está conectada.\n\nScopes: `messages:send`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"type":{"default":"text","type":"string","enum":["text","image","video","audio","document","template"]},"template":{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"components":{"description":"Parámetros de la plantilla como en la Cloud API de Meta (`header`, `body`, `button`). En una cabecera de imagen, video o documento, el archivo puede ir por `uploadId` (de `POST /v1/media/uploads`) en lugar de `id`/`link`: `{ \"type\": \"header\", \"parameters\": [{ \"type\": \"document\", \"document\": { \"uploadId\": \"upl_…\", \"filename\": \"Factura.pdf\" } }] }` (`image`/`video` igual, sin `filename`). El tipo debe coincidir con la cabecera de la plantilla; imagen JPEG/PNG ≤ 5 MB, video MP4/3GPP ≤ 16 MB, documento ≤ 100 MB. Sin `header`, se usa el archivo predeterminado de la plantilla si lo tiene.","maxItems":20,"type":"array","items":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{}}}},"required":["name","language"],"additionalProperties":false},"text":{"type":"string"},"uploadId":{"type":"string","minLength":5,"maxLength":64},"caption":{"type":"string","maxLength":4096},"fileName":{"type":"string","minLength":1,"maxLength":255},"quotedMessageId":{"type":"string","minLength":5,"maxLength":64},"mentions":{"maxItems":256,"type":"array","items":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}},"mentionAll":{"type":"boolean"}},"additionalProperties":false}}}},"security":[{"apiKey":["messages:send"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/participants":{"get":{"operationId":"get_groups_by_id_participants","tags":["groups"],"summary":"Participantes de un grupo","description":"Scopes: `conversations:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"includeLeft","in":"query","required":false,"schema":{"type":"string","enum":["0","1","true","false"]}},{"name":"limit","in":"query","required":false,"schema":{"default":200,"type":"integer","minimum":1,"maximum":500}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["conversations:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/GroupParticipant"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_groups_by_id_participants","tags":["groups"],"summary":"Quitar, promover o degradar participantes","description":"Quitar del grupo, dar admin o quitar admin; resultado por participante.\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"action":{"type":"string","enum":["remove","promote","demote"]},"participantIds":{"minItems":1,"maxItems":50,"type":"array","items":{"type":"string","minLength":5,"maxLength":64}}},"required":["action","participantIds"],"additionalProperties":false}}}},"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"groupId":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"results":{"type":"array","items":{"type":"object","properties":{"participantId":{"type":"string","pattern":"^gpt_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`gpt_…`)."},"ok":{"type":"boolean"},"reason":{"type":["string","null"]}},"required":["participantId","ok","reason"]}}},"required":["groupId","results"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_groups_by_id_participants","tags":["groups"],"summary":"Añadir participantes a un grupo","description":"Añadir participantes por número; resultado por número.\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"phones":{"minItems":1,"maxItems":50,"type":"array","items":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}}},"required":["phones"],"additionalProperties":false}}}},"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"groupId":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"results":{"type":"array","items":{"type":"object","properties":{"phone":{"type":"string"},"ok":{"type":"boolean"},"reason":{"type":["string","null"]}},"required":["phone","ok","reason"]}}},"required":["groupId","results"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/groups/{id}/picture":{"put":{"operationId":"put_groups_by_id_picture","tags":["groups"],"summary":"Cambiar la foto de un grupo","description":"Foto nueva del grupo desde una subida (`POST /v1/media/uploads`, JPG o PNG).\n\nScopes: `groups:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"uploadId":{"type":"string","minLength":5,"maxLength":64}},"required":["uploadId"],"additionalProperties":false}}}},"security":[{"apiKey":["groups:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"groupId":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"status":{"type":"string","const":"applied"}},"required":["groupId","status"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/integrations/google-contacts":{"delete":{"operationId":"delete_integrations_google_contacts","tags":["integrations"],"summary":"Desconectar Google Contacts","description":"Desconectar: revoca el token en Google y conserva los contactos de WAQR (vínculos `unlinked`).\n\nScopes: `integrations:manage`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["integrations:manage"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_integrations_google_contacts","tags":["integrations"],"summary":"Estado de la integración con Google Contacts","description":"Estado de la integración de Google Contacts de la organización.\n\nScopes: `integrations:manage`.","security":[{"apiKey":["integrations:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"type":"boolean","description":"La integración está disponible en la plataforma."},"integration":{"anyOf":[{"$ref":"#/components/schemas/GoogleContactsIntegration"},{"type":"null"}],"description":"Null si la organización no la ha conectado."}},"required":["enabled","integration"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/integrations/google-contacts/settings":{"patch":{"operationId":"patch_integrations_google_contacts_settings","tags":["integrations"],"summary":"Ajustes de Google Contacts","description":"`syncScope` (`saved` | `all_with_number`) e `importContacts`.\n\nScopes: `integrations:manage`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"syncScope":{"type":"string","enum":["saved","all_with_number"]},"importContacts":{"type":"boolean"}},"additionalProperties":false}}}},"security":[{"apiKey":["integrations:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"integration":{"$ref":"#/components/schemas/GoogleContactsIntegration"}},"required":["integration"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/integrations/google-contacts/sync":{"post":{"operationId":"post_integrations_google_contacts_sync","tags":["integrations"],"summary":"Pedir una sincronización con Google Contacts","description":"Scopes: `integrations:manage`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["integrations:manage"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"integration":{"$ref":"#/components/schemas/GoogleContactsIntegration"}},"required":["integration"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/leads":{"get":{"operationId":"get_leads","tags":["leads"],"summary":"Listar leads web","description":"Lista paginada de leads (más recientes primero) con su contexto y el estado de bienvenida, respuesta y recordatorio: `?connectionId&from&to&page&pageSize` (por defecto, los últimos 30 días). Sesión con `contacts.read` o API key con `contacts:read`; respeta el alcance por conexión.\n\nScopes: `contacts:read`.","parameters":[{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"from","in":"query","required":false,"schema":{"type":"string"}},{"name":"to","in":"query","required":false,"schema":{"type":"string"}},{"name":"page","in":"query","required":false,"schema":{"default":1,"type":"integer","minimum":1,"maximum":10000}},{"name":"pageSize","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}}],"security":[{"apiKey":["contacts:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Lead"}},"page":{"type":"integer"},"pageSize":{"type":"integer"},"total":{"type":"integer"},"from":{"type":"string","format":"date-time"},"to":{"type":"string","format":"date-time"}},"required":["data","page","pageSize","total","from","to"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_leads","tags":["leads"],"summary":"Registrar un lead web (y enviar la bienvenida)","description":"Un lead de una web (plugin de WordPress u otra integración) con su contexto (página, producto, formulario, tema, consentimiento). Crea o actualiza el contacto por teléfono en la organización, guarda el lead y decide la bienvenida en el servidor (QR → texto con variables; oficial/coexistencia → plantilla aprobada) con el anti-spam por conexión (7 días, tope diario, BAJA). API key con `leads:write` (una clave limitada a conexiones solo escribe en las suyas: fuera de su alcance, 404) o sesión con `contacts.write`. `Idempotency-Key` obligatoria. → `201 { lead: { id, contactId, conversationId }, welcome: { status, reason? } }`.\n\nScopes: `leads:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"connectionId":{"type":"string","minLength":5,"maxLength":64},"phone":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"},"name":{"anyOf":[{"type":"string","maxLength":128},{"type":"null"}]},"email":{"anyOf":[{"type":"string","maxLength":190,"format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"},{"type":"null"}]},"source":{"default":"api","type":"string","maxLength":40},"site":{"anyOf":[{"type":"string","maxLength":2000},{"type":"null"}]},"page":{"anyOf":[{"type":"object","properties":{"url":{"anyOf":[{"type":"string","maxLength":2000},{"type":"null"}]},"title":{"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]}},"additionalProperties":false},{"type":"null"}]},"product":{"anyOf":[{"type":"object","properties":{"id":{"anyOf":[{"type":"string","maxLength":64},{"type":"null"}]},"name":{"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]},"price":{"anyOf":[{"type":"string","maxLength":40},{"type":"null"}]},"currency":{"anyOf":[{"type":"string","pattern":"^[A-Za-z]{3}$"},{"type":"null"}]},"url":{"anyOf":[{"type":"string","maxLength":2000},{"type":"null"}]}},"additionalProperties":false},{"type":"null"}]},"form":{"anyOf":[{"type":"object","properties":{"id":{"anyOf":[{"type":"string","maxLength":64},{"type":"null"}]},"name":{"anyOf":[{"type":"string","maxLength":120},{"type":"null"}]},"fields":{"maxItems":30,"type":"array","items":{"type":"object","properties":{"label":{"type":"string","maxLength":120},"value":{"type":"string","maxLength":2000}},"required":["label","value"],"additionalProperties":false}}},"additionalProperties":false},{"type":"null"}]},"topic":{"anyOf":[{"type":"string","maxLength":120},{"type":"null"}]},"variant":{"anyOf":[{"type":"string","enum":["form","product","page"]},{"type":"null"}]},"consent":{"anyOf":[{"type":"object","properties":{"text":{"type":"string","maxLength":1000},"at":{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"}},"required":["text","at"],"additionalProperties":false},{"type":"null"}]}},"required":["connectionId","phone"],"additionalProperties":false}}}},"security":[{"apiKey":["leads:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"lead":{"type":"object","properties":{"id":{"type":"string","pattern":"^lead_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`lead_…`)."},"contactId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"conversationId":{"anyOf":[{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},{"type":"null"}]}},"required":["id","contactId","conversationId"]},"welcome":{"type":"object","properties":{"status":{"type":"string","description":"`queued` o `skipped`."},"reason":{"type":"string"}},"required":["status"]}},"required":["lead","welcome"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/leads/metrics":{"get":{"operationId":"get_leads_metrics","tags":["leads"],"summary":"Métricas de leads web","description":"Métricas de los leads web `?connectionId&from&to` → `{ leads, welcomed, replied, replyRate, medianMinutesToReply, medianMinutesToHumanReply, byVariant, optOuts, from, to }`.\n\nScopes: `contacts:read`.","parameters":[{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"from","in":"query","required":false,"schema":{"type":"string"}},{"name":"to","in":"query","required":false,"schema":{"type":"string"}}],"security":[{"apiKey":["contacts:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"leads":{"type":"integer"},"welcomed":{"type":"integer"},"replied":{"type":"integer"},"replyRate":{"type":"number","description":"De 0 a 1."},"medianMinutesToReply":{"type":["number","null"]},"medianMinutesToHumanReply":{"type":["number","null"]},"byVariant":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"object","properties":{"leads":{"type":"integer"},"welcomed":{"type":"integer"},"replied":{"type":"integer"},"replyRate":{"type":"number"}},"required":["leads","welcomed","replied","replyRate"]}},"optOuts":{"type":"integer"},"from":{"type":"string","format":"date-time"},"to":{"type":"string","format":"date-time"}},"required":["leads","welcomed","replied","replyRate","medianMinutesToReply","medianMinutesToHumanReply","byVariant","optOuts","from","to"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/media/uploads":{"post":{"operationId":"post_media_uploads","tags":["media"],"summary":"Subir un archivo para enviarlo","description":"Subir un adjunto para enviarlo después: `multipart/form-data` con la parte `file` (y `kind` opcional). Sesión con `inbox.reply` o API key con `messages:send`. 201 con `{ upload: { id: 'upl_…', mimeType, size, fileName, kind, expiresAt } }`; la subida vale 24 h y se usa con `uploadId` en `POST /v1/conversations/{id}/messages` o `POST /v1/messages`.\n\nScopes: `messages:send`.","security":[{"apiKey":["messages:send"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"upload":{"$ref":"#/components/schemas/Upload"}},"required":["upload"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages":{"post":{"operationId":"post_messages","tags":["messages"],"summary":"Enviar un mensaje a un número o usuario","description":"Enviar un texto o un adjunto a un número E.164 (`to`), a un contacto (`contactId`) o, en WhatsApp oficial, al BSUID de una persona sin número conocido desde una conexión: reutiliza la conversación 1:1 si existe y, si no, la crea (límite más bajo para números nuevos). Un destinatario por petición: no hay envío masivo. 202 con el mensaje `pending`. `Idempotency-Key` obligatoria.\n\nScopes: `messages:send`.","parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"connectionId":{"type":"string","minLength":5,"maxLength":64},"to":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"},"contactId":{"type":"string","minLength":5,"maxLength":64},"toUserId":{"type":"string","pattern":"^[A-Z]{2}(?:\\.ENT)?\\.[A-Za-z0-9]{1,128}$"},"type":{"default":"text","type":"string","enum":["text","image","video","audio","document","template"]},"template":{"type":"object","properties":{"name":{"type":"string","pattern":"^[a-z0-9_]{1,512}$"},"language":{"type":"string","pattern":"^[A-Za-z]{2,3}(_[A-Za-z0-9]{2,8})?$"},"components":{"description":"Parámetros de la plantilla como en la Cloud API de Meta (`header`, `body`, `button`). En una cabecera de imagen, video o documento, el archivo puede ir por `uploadId` (de `POST /v1/media/uploads`) en lugar de `id`/`link`: `{ \"type\": \"header\", \"parameters\": [{ \"type\": \"document\", \"document\": { \"uploadId\": \"upl_…\", \"filename\": \"Factura.pdf\" } }] }` (`image`/`video` igual, sin `filename`). El tipo debe coincidir con la cabecera de la plantilla; imagen JPEG/PNG ≤ 5 MB, video MP4/3GPP ≤ 16 MB, documento ≤ 100 MB. Sin `header`, se usa el archivo predeterminado de la plantilla si lo tiene.","maxItems":20,"type":"array","items":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{}}}},"required":["name","language"],"additionalProperties":false},"text":{"type":"string"},"uploadId":{"type":"string","minLength":5,"maxLength":64},"caption":{"type":"string","maxLength":4096},"fileName":{"type":"string","minLength":1,"maxLength":255},"quotedMessageId":{"type":"string","minLength":5,"maxLength":64},"mentions":{"maxItems":256,"type":"array","items":{"type":"string","pattern":"^\\+[1-9]\\d{6,14}$"}},"mentionAll":{"type":"boolean"}},"required":["connectionId"],"additionalProperties":false}}}},"security":[{"apiKey":["messages:send"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}":{"delete":{"operationId":"delete_messages_by_id","tags":["messages"],"summary":"Eliminar un mensaje","description":"`?scope=me` (por defecto) oculta el mensaje en WAQR para todo el equipo («eliminar para mí»; se recupera con `POST …/unhide`); `?scope=everyone` lo elimina también en WhatsApp (solo QR; el autor, o `inbox.messages.manage`).\n\nScopes: `messages:send`, `messages:manage`, `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"scope","in":"query","required":false,"schema":{"default":"me","type":"string","enum":["me","everyone"]}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["messages:send","messages:manage","conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"anyOf":[{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"deleted":{"type":"boolean","const":true}},"required":["messageId","conversationId","connectionId","deleted"],"description":"Con `?scope=everyone`."},{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"],"description":"Sin `scope=everyone`: se oculta solo en WAQR."}]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_messages_by_id","tags":["messages"],"summary":"Ver un mensaje","description":"Scopes: `messages:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_messages_by_id","tags":["messages"],"summary":"Editar un mensaje enviado","description":"Editar el texto de un mensaje propio (solo QR; menos de 15 min; el autor, o `inbox.messages.manage`). Se aplica en WhatsApp y después en WAQR.\n\nScopes: `messages:send`, `messages:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string","minLength":1,"maxLength":4096}},"required":["text"],"additionalProperties":false}}}},"security":[{"apiKey":["messages:send","messages:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"edited":{"type":"boolean","const":true}},"required":["messageId","conversationId","connectionId","edited"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/attachments/{aid}":{"get":{"operationId":"get_messages_by_id_attachments_by_aid","tags":["messages"],"summary":"Descargar un adjunto (URL firmada)","description":"Descargar un adjunto: `302` a una URL firmada del bucket privado, de vida corta (`mediaSignedUrlTtlSeconds`, 5 min). Con `?redirect=false`, `200 { attachment: { url, expiresAt, … } }` (para clientes que no siguen redirecciones). Nunca hay media pública.\n\nScopes: `messages:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"aid","in":"path","required":true,"schema":{"type":"string"}},{"name":"redirect","in":"query","required":false,"schema":{"type":"string","enum":["0","1","true","false"]}}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK. Con `?redirect=false`.","content":{"application/json":{"schema":{"type":"object","properties":{"attachment":{"type":"object","properties":{"url":{"type":"string","description":"URL firmada de descarga (caduca)."},"expiresAt":{"type":"string","format":"date-time"},"mimeType":{"type":["string","null"]},"fileName":{"type":["string","null"]},"sizeBytes":{"anyOf":[{"type":"integer"},{"type":"null"}]},"sha256":{"type":["string","null"]}},"required":["url","expiresAt","mimeType","fileName","sizeBytes","sha256"]}},"required":["attachment"]}}}},"302":{"description":"Redirección a la URL firmada del archivo (sin `?redirect=false`).","headers":{"Location":{"schema":{"type":"string"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/forward":{"post":{"operationId":"post_messages_by_id_forward","tags":["messages"],"summary":"Reenviar un mensaje","description":"Reenviar el contenido de un mensaje a hasta 5 conversaciones. Cada reenvío sale por la cola de envío normal (límites, ventana de 24 h de oficial); el resultado va por conversación. `Idempotency-Key` obligatoria.\n\nScopes: `messages:send`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"conversationIds":{"minItems":1,"maxItems":5,"type":"array","items":{"type":"string","minLength":5,"maxLength":64}}},"required":["conversationIds"],"additionalProperties":false}}}},"security":[{"apiKey":["messages:send"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"results":{"type":"array","items":{"type":"object","properties":{"conversationId":{"type":"string"},"ok":{"type":"boolean"},"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"reason":{"description":"Código del error si esa copia falló.","type":"string"},"detail":{"type":"string"}},"required":["conversationId","ok"]}}},"required":["messageId","results"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/info":{"get":{"operationId":"get_messages_by_id_info","tags":["messages"],"summary":"Entrega y lectura de un mensaje","description":"«Info del mensaje» (enviado, entregado, leído, quién lo mandó, reenviado, editado).\n\nScopes: `messages:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"info":{"$ref":"#/components/schemas/MessageInfo"}},"required":["info"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/pin":{"delete":{"operationId":"delete_messages_by_id_pin","tags":["messages"],"summary":"Desfijar un mensaje","description":"Scopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversation":{"$ref":"#/components/schemas/Conversation"}},"required":["conversation"]},"example":{"conversation":{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_messages_by_id_pin","tags":["messages"],"summary":"Fijar un mensaje","description":"Fijar un mensaje arriba del chat (`PUT { duration?: '24h'|'7d'|'30d' }`, máx. 3 por chat → `409 pin_limit_reached`) o desfijarlo (`DELETE`). Devuelve la conversación con `pinnedMessages`.\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"duration":{"anyOf":[{"type":"string","enum":["24h","7d","30d"]},{"type":"null"}]}},"additionalProperties":false}}}},"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"conversation":{"$ref":"#/components/schemas/Conversation"}},"required":["conversation"]},"example":{"conversation":{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/reaction":{"delete":{"operationId":"delete_messages_by_id_reaction","tags":["messages"],"summary":"Quitar la reacción","description":"Quitar la reacción propia.\n\nScopes: `messages:send`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["messages:send"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"reactionMessageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"emoji":{"type":["string","null"]}},"required":["messageId","reactionMessageId","emoji"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_messages_by_id_reaction","tags":["messages"],"summary":"Reaccionar a un mensaje","description":"Reaccionar a un mensaje (`emoji` vacío = quitar la reacción). QR y WhatsApp oficial.\n\nScopes: `messages:send`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"emoji":{"type":"string","maxLength":16}},"required":["emoji"],"additionalProperties":false}}}},"security":[{"apiKey":["messages:send"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"reactionMessageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"emoji":{"type":["string","null"]}},"required":["messageId","reactionMessageId","emoji"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/star":{"delete":{"operationId":"delete_messages_by_id_star","tags":["messages"],"summary":"Quitar el destacado","description":"Scopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_messages_by_id_star","tags":["messages"],"summary":"Destacar un mensaje","description":"Destacar (`PUT`) o quitar el destacado (`DELETE`) de un mensaje; del equipo, solo en WAQR.\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/{id}/unhide":{"post":{"operationId":"post_messages_by_id_unhide","tags":["messages"],"summary":"Volver a mostrar un mensaje oculto","description":"Recuperar un mensaje oculto con «eliminar para mí».\n\nScopes: `conversations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["conversations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"$ref":"#/components/schemas/Message"}},"required":["message"]},"example":{"message":{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/messages/starred":{"get":{"operationId":"get_messages_starred","tags":["messages"],"summary":"Mensajes destacados","description":"Mensajes destacados de toda la organización (`?limit=&cursor=`), los últimos primero.\n\nScopes: `messages:read`.","parameters":[{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":512}}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Message"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]},"example":{"data":[{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}],"nextCursor":null}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner":{"get":{"operationId":"get_partner","tags":["partner"],"summary":"Resumen del revendedor","description":"Resumen del partner: estado, capacidad (total, asignado, disponible) y clientes.\n\nScopes: `partner:read`.","security":[{"apiKey":["partner:read"]},{"partnerToken":["partner:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"partner":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"name":{"type":"string"},"partnerStatus":{"type":"string","enum":["pending","active","suspended"],"description":"Aprobación del partner; solo `active` tiene capacidad efectiva."},"status":{"type":"string","enum":["active","suspended","closed"]},"billingMode":{"type":"string","enum":["included","external","partner_paypal"],"description":"Quién cobra a los clientes."},"active":{"type":"boolean"},"partnerType":{"type":"string","enum":["internal","external"]},"slug":{"description":"Solo revendedores internos.","type":["string","null"]},"accessUrl":{"description":"Dirección donde entran tus clientes (revendedores internos).","type":["string","null"]}},"required":["id","name","partnerStatus","status","billingMode","active","partnerType","slug","accessUrl"]},"internalCapacity":{"anyOf":[{"type":"object","properties":{"unlimited":{"type":"boolean"},"cap":{"anyOf":[{"type":"integer"},{"type":"null"}]},"used":{"type":"integer"},"available":{"anyOf":[{"type":"integer"},{"type":"null"}]}},"required":["unlimited","cap","used","available"]},{"type":"null"}],"description":"Solo revendedores internos (sin bolsa): conexiones usadas y tope; null en los demás."},"capacity":{"type":"array","items":{"$ref":"#/components/schemas/CapacityPool"}},"features":{"type":"array","items":{"type":"object","properties":{"feature":{"type":"string"},"enabled":{"type":"boolean"},"maxQuantity":{"anyOf":[{"type":"integer"},{"type":"null"}]}},"required":["feature","enabled","maxQuantity"]}},"fees":{"anyOf":[{"type":"object","properties":{"blocked":{"type":"boolean"}},"required":["blocked"]},{"type":"null"}],"description":"Cuotas con WAQR: null si no pagas cuota; `blocked` = cuota vencida y uso de tus clientes pausado."},"customers":{"type":"object","properties":{"total":{"type":"integer"},"active":{"type":"integer"},"suspended":{"type":"integer"}},"required":["total","active","suspended"]}},"required":["partner","internalCapacity","capacity","features","fees","customers"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/agent-credits":{"get":{"operationId":"get_partner_agent_credits","tags":["partner"],"summary":"Créditos de IA del revendedor","description":"Créditos de IA del revendedor: billetera → `{ balance, lots, packages, ledger, billingEnabled, purchase }`. Panel (sesión) o API de partners con `partner:read`.\n\nScopes: `partner:read`.","security":[{"apiKey":["partner:read"]},{"partnerToken":["partner:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"balance":{"type":"integer","description":"Créditos disponibles en tu billetera."},"lots":{"type":"array","items":{"$ref":"#/components/schemas/CreditLot"}},"packages":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"credits":{"type":"integer"},"priceCents":{"type":"integer"},"currency":{"type":"string"},"active":{"type":"boolean"},"expiresInDays":{"type":"integer","description":"Días de vigencia de los créditos comprados."}},"required":["id","credits","priceCents","currency","active","expiresInDays"]},"description":"Paquetes de créditos a la venta."},"billingEnabled":{"type":"boolean"},"purchase":{"type":"object","properties":{"allowed":{"type":"boolean"},"reason":{"anyOf":[{"type":"string","const":"billing_disabled"},{"type":"null"}]}},"required":["allowed","reason"]},"ledger":{"type":"array","items":{"$ref":"#/components/schemas/CreditLedgerEntry"}}},"required":["balance","lots","packages","billingEnabled","purchase","ledger"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers":{"get":{"operationId":"get_partner_api_customers","tags":["partner-api"],"summary":"Listar clientes (por externalId)","description":"Clientes del revendedor por su `externalId`. Bearer de la API de partners; también la sesión del panel o una API key de partner con los mismos scopes. - `GET ?status=&cursor=&limit=` → `{ data: Customer[], nextCursor }` (sin dados de baja salvo `status=deleted`; `limit` 1–100, 50 por defecto). - `POST { externalId, name, country?, timezone?, owner: { email, name }, plan?: { connections?, status? }, sendInvite? }` → `201 { customer, created: true }`; mismo `externalId` → `200 { customer, created: false }` (dado de baja → se restaura, `restored: true`) · `409 partner_inactive` · `429` (120/h por revendedor). `Idempotency-Key` OPCIONAL: el alta ya es idempotente por `externalId`, así que es la excepción a «lo que crea recursos en `/v1/partner/*` exige `Idempotency-Key`»; si viene, se aplica (`idempotency` por defecto).\n\nScopes: `partner:customers:read`.","parameters":[{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["active","past_due","suspended","canceled","deleted"]}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}}],"security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/PartnerCustomer"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_api_customers","tags":["partner-api"],"summary":"Dar de alta o actualizar un cliente por externalId","description":"Scopes: `partner:customers:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"externalId":{"type":"string","minLength":1,"maxLength":128,"pattern":"^[\\x21-\\x7e]+$"},"name":{"type":"string","minLength":1,"maxLength":120},"country":{"type":"string","minLength":2,"maxLength":2},"timezone":{"type":"string","minLength":3,"maxLength":64},"owner":{"type":"object","properties":{"email":{"type":"string","maxLength":254,"format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"},"name":{"type":"string","minLength":1,"maxLength":120}},"required":["email","name"]},"plan":{"type":"object","properties":{"connections":{"anyOf":[{"type":"integer","minimum":0,"maximum":10000},{"type":"null"}]},"status":{"type":"string","enum":["active","suspended"]},"historyImport":{"type":"boolean"}}},"embed":{"type":"object","properties":{"engines":{"anyOf":[{"minItems":1,"maxItems":2,"type":"array","items":{"type":"string","enum":["qr","waba"]}},{"type":"null"}]}},"required":["engines"]},"sendInvite":{"type":"boolean"}},"required":["externalId","name","owner"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/PartnerCustomer"},"created":{"type":"boolean","description":"`true` (201) si se creó; `false` (200) si ya existía."},"restored":{"description":"Estaba dado de baja y se restauró.","type":"boolean","const":true}},"required":["customer","created"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}":{"delete":{"operationId":"delete_partner_api_customers_by_externalId","tags":["partner-api"],"summary":"Dar de baja un cliente","description":"Scopes: `partner:customers:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/PartnerCustomer"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_partner_api_customers_by_externalId","tags":["partner-api"],"summary":"Ver un cliente","description":"Un cliente por su `externalId` (de otro partner → 404). - `GET` → `{ customer }` (también dado de baja: `status: 'deleted'`). - `PATCH { name?, country?, timezone?, plan?: { connections?, status? } }` → `{ customer }` · `409 customer_deleted`. - `DELETE` → `200 { customer }` con `status: 'deleted'` y `deletedAt`: baja lógica. Idempotente.\n\nScopes: `partner:customers:read`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/PartnerCustomer"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_partner_api_customers_by_externalId","tags":["partner-api"],"summary":"Cambiar nombre o plan de un cliente","description":"Scopes: `partner:customers:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":120},"country":{"type":"string","minLength":2,"maxLength":2},"timezone":{"type":"string","minLength":3,"maxLength":64},"plan":{"type":"object","properties":{"connections":{"anyOf":[{"type":"integer","minimum":0,"maximum":10000},{"type":"null"}]},"status":{"type":"string","enum":["active","suspended"]},"historyImport":{"type":"boolean"}}},"embed":{"type":"object","properties":{"engines":{"anyOf":[{"minItems":1,"maxItems":2,"type":"array","items":{"type":"string","enum":["qr","waba"]}},{"type":"null"}]}},"required":["engines"]}}}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/PartnerCustomer"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/api-keys":{"get":{"operationId":"get_partner_api_customers_by_externalId_api_keys","tags":["partner-api"],"summary":"Claves de API de un cliente","description":"API keys de integración de UN cliente del revendedor (las crea su usuario de integración, rol `agent` en el cliente). `GET` → `200 { data: ApiKey[], customer: { id, externalId } }` (solo las de la integración, más recientes primero; nunca el secreto).\n\nScopes: `partner:api-keys:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"security":[{"apiKey":["partner:api-keys:manage"]},{"partnerToken":["partner:api-keys:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ApiKey"}},"customer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"externalId":{"type":["string","null"]}},"required":["id","externalId"]}},"required":["data","customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_api_customers_by_externalId_api_keys","tags":["partner-api"],"summary":"Emitir una clave de API para un cliente","description":"`{ name?, scopes? (por defecto connections:read, messages:read, messages:send), expiresAt? }` → `201 { apiKey, secret: 'wq_live_…', customer }`: el secreto solo aquí. `404` (externalId de otro partner) · `409 customer_deleted` · `403 scope_exceeds_role` (fuera del techo `agent`) · `422 validation_failed` · `409 api_key_limit_reached` · `409 partner_inactive` · `429`. Sin Idempotency-Key: la respuesta lleva un secreto que no se guarda.\n\nScopes: `partner:api-keys:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":80},"scopes":{"minItems":1,"maxItems":30,"type":"array","items":{"type":"string","minLength":1,"maxLength":64}},"expiresAt":{"anyOf":[{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"},{"type":"null"}]}}}}}},"security":[{"apiKey":["partner:api-keys:manage"]},{"partnerToken":["partner:api-keys:manage"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"apiKey":{"$ref":"#/components/schemas/ApiKey"},"secret":{"type":"string","description":"Secreto `wq_live_…`: se muestra solo esta vez."},"customer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"externalId":{"type":["string","null"]}},"required":["id","externalId"]}},"required":["apiKey","secret","customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/api-keys/{keyId}":{"delete":{"operationId":"delete_partner_api_customers_by_externalId_api_keys_by_keyId","tags":["partner-api"],"summary":"Revocar una clave de API de un cliente","description":"Revocar una API key de integración del cliente → `200 { apiKey }` con `status: 'revoked'` (idempotente; deja de valer al momento). Una clave que no es de la integración de ESTE revendedor en ESE cliente → `404`.\n\nScopes: `partner:api-keys:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:api-keys:manage"]},{"partnerToken":["partner:api-keys:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"apiKey":{"$ref":"#/components/schemas/ApiKey"}},"required":["apiKey"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/connections":{"get":{"operationId":"get_partner_api_customers_by_externalId_connections","tags":["partner-api"],"summary":"Conexiones de un cliente","description":"Conexiones de un cliente por su `externalId` → `{ data: Connection[] }` (mismo DTO que `/v1/connections`, con `engine`, `waba`, `status` y `pausedReason`; incluye las pausadas).\n\nScopes: `partner:customers:read`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}}},"required":["data"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/connections/{connectionId}":{"delete":{"operationId":"delete_partner_api_customers_by_externalId_connections_by_connectionId","tags":["partner-api"],"summary":"Eliminar una conexión de un cliente","description":"Borra una conexión del cliente (mismo servicio que `DELETE /v1/connections/{id}`; en WhatsApp oficial deja de recibir y enviar, el número sigue en la WABA del cliente) → `204`. Idempotente; de otro cliente o partner → `404`. Con plaza libre se reanudan las pausadas por `plan_limit`.\n\nScopes: `partner:connections:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/connections/{connectionId}/templates":{"get":{"operationId":"get_partner_api_customers_by_externalId_connections_by_connectionId_templates","tags":["partner-api"],"summary":"Plantillas de una conexión de un cliente","description":"Plantillas de WhatsApp oficial de una conexión de un cliente del revendedor (mismo contrato que `/v1/connections/{id}/templates`) → `{ templates: [...] }`. `404` (externalId de otro partner o conexión de otro cliente) · `409 not_supported_for_engine` (conexión QR).\n\nScopes: `partner:templates:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."}],"security":[{"apiKey":["partner:templates:manage"]},{"partnerToken":["partner:templates:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"templates":{"type":"array","items":{"$ref":"#/components/schemas/Template"}}},"required":["templates"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_api_customers_by_externalId_connections_by_connectionId_templates","tags":["partner-api"],"summary":"Crear una plantilla para un cliente","description":"Crea una plantilla (validada como Meta) → `201 { template }`. Mismos errores y límite (`wabaTemplateCreate` 20/h por conexión) que `POST /v1/connections/{id}/templates`; además `409 customer_deleted` y `409 partner_inactive`.\n\nScopes: `partner:templates:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":600},"language":{"type":"string","minLength":2,"maxLength":12},"category":{"type":"string","enum":["MARKETING","UTILITY","AUTHENTICATION"]},"header":{"type":"object","properties":{"format":{"type":"string","enum":["TEXT","IMAGE","DOCUMENT","VIDEO"]},"text":{"type":"string","maxLength":4096},"example":{"type":"string","maxLength":4096}},"required":["format"],"additionalProperties":false},"body":{"type":"object","properties":{"text":{"type":"string","maxLength":8192},"examples":{"anyOf":[{"maxItems":100,"type":"array","items":{"type":"string","maxLength":4096}},{"type":"object","propertyNames":{"type":"string","maxLength":100},"additionalProperties":{"type":"string","maxLength":4096}}]}},"required":["text"],"additionalProperties":false},"footer":{"type":"string","maxLength":4096},"buttons":{"maxItems":20,"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["QUICK_REPLY","URL","PHONE_NUMBER"]},"text":{"type":"string","maxLength":4096},"url":{"type":"string","maxLength":4096},"phoneNumber":{"type":"string","maxLength":64},"example":{"type":"string","maxLength":4096}},"required":["type","text"],"additionalProperties":false}},"authentication":{"type":"object","properties":{"addSecurityRecommendation":{"type":"boolean"},"codeExpirationMinutes":{"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},"buttonText":{"type":"string","maxLength":4096}},"additionalProperties":false}},"required":["name","language","category"],"additionalProperties":false}}}},"security":[{"apiKey":["partner:templates:manage"]},{"partnerToken":["partner:templates:manage"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"template":{"$ref":"#/components/schemas/Template"}},"required":["template"]},"example":{"template":{"name":"confirmacion_pedido","language":"es","category":"UTILITY","status":"APPROVED","parameterFormat":"POSITIONAL","rejectedReason":null,"components":[{"type":"HEADER","format":"IMAGE"},{"type":"BODY","text":"Hola {{1}}, tu pedido {{2}} está confirmado."},{"type":"FOOTER","text":"Tienda Ejemplo"}],"previousCategory":null,"categoryChangedAt":null,"statusChangedAt":"2026-11-28T12:00:00.000Z","createdAt":"2026-11-28T11:58:00.000Z","updatedAt":"2026-11-28T12:00:00.000Z","headerFormat":"IMAGE","variables":{"header":[],"body":["1","2"],"buttons":[]},"preview":{"header":"[imagen]","body":"Hola {{1}}, tu pedido {{2}} está confirmado.","footer":"Tienda Ejemplo"},"headerDefault":{"mimeType":"image/jpeg","fileName":"pedido.jpg","sizeBytes":48213,"setAt":"2026-11-28T12:05:00.000Z"}}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/connections/{connectionId}/templates/{name}":{"delete":{"operationId":"delete_partner_api_customers_by_externalId_connections_by_connectionId_templates_by_name","tags":["partner-api"],"summary":"Eliminar una plantilla de un cliente","description":"Elimina una plantilla de una conexión de un cliente del revendedor → `204` (sin `?language=`, todos los idiomas con ese nombre). `404 waba_template_not_found` si no existe.\n\nScopes: `partner:templates:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"name","in":"path","required":true,"schema":{"type":"string"},"description":"Nombre de la plantilla de WhatsApp."},{"name":"language","in":"query","required":false,"schema":{"type":"string","minLength":2,"maxLength":12}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:templates:manage"]},{"partnerToken":["partner:templates:manage"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/connections/{connectionId}/templates/sync":{"delete":{"operationId":"delete_partner_api_customers_by_externalId_connections_by_connectionId_templates_sync","tags":["partner-api"],"summary":"Eliminar la plantilla llamada «sync» de un cliente","description":"Una plantilla que se llama «sync» (nombre válido en Meta): mismo `DELETE` que `templates/{name}`.\n\nScopes: `partner:templates:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"language","in":"query","required":false,"schema":{"type":"string","minLength":2,"maxLength":12}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:templates:manage"]},{"partnerToken":["partner:templates:manage"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_api_customers_by_externalId_connections_by_connectionId_templates_sync","tags":["partner-api"],"summary":"Refrescar las plantillas de un cliente desde Meta","description":"Relee de Meta las plantillas de una conexión de un cliente del revendedor → `{ templates, syncedAt }` (mismo contrato y límite que `POST /v1/connections/{id}/templates/sync`).\n\nScopes: `partner:templates:manage`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:templates:manage"]},{"partnerToken":["partner:templates:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"templates":{"type":"array","items":{"$ref":"#/components/schemas/Template"}},"syncedAt":{"type":"string","format":"date-time"}},"required":["templates","syncedAt"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/embed-sessions":{"post":{"operationId":"post_partner_api_customers_by_externalId_embed_sessions","tags":["partner-api"],"summary":"Código de un uso para embeber «Vincular WhatsApp» de un cliente","description":"El SaaS del revendedor pide un código de un uso para embeber la superficie de UN cliente suyo. `{ surface: 'connections', parentOrigin }` → `201 { code: 'ec_…', expiresAt, expiresInSeconds: 60, surface, embedUrl: 'https://<host>/embed/v1/connections' }`. `404` (externalId de otro partner) · `404 embed_disabled` · `409 embed_not_available` · `403 origin_not_allowed` · `400 invalid_parent_origin` · `409 surface_not_embedded` · `409 customer_deleted` · `429` (60/min por partner y cliente). Sin `Idempotency-Key`: el código es de un solo uso y nunca se repite ni se cachea.\n\nScopes: `partner:connections:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"surface":{"type":"string","const":"connections"},"parentOrigin":{"type":"string","minLength":1,"maxLength":300},"engines":{"minItems":1,"maxItems":2,"type":"array","items":{"type":"string","enum":["qr","waba"]}}},"required":["surface","parentOrigin"]}}}},"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"string","description":"Código de un uso para abrir el embebido."},"expiresAt":{"type":"string","format":"date-time"},"expiresInSeconds":{"type":"integer"},"surface":{"type":"string"},"embedUrl":{"type":"string"}},"required":["code","expiresAt","expiresInSeconds","surface","embedUrl"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/embed/origins":{"get":{"operationId":"get_partner_api_customers_by_externalId_embed_origins","tags":["partner-api"],"summary":"Orígenes permitidos del embebido de un cliente","description":"Orígenes del embebido de UN cliente del revendedor, además de los del partner → `{ origins, effectiveOrigins }` (`effectiveOrigins` = los del partner más los del cliente, lo que vale al emitir una sesión). `404` (externalId de otro partner) · `409 embed_not_available` (revendedor no interno).\n\nScopes: `partner:connections:read`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"security":[{"apiKey":["partner:connections:read"]},{"partnerToken":["partner:connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"origins":{"type":"array","items":{"type":"string"}},"effectiveOrigins":{"type":"array","items":{"type":"string"}}},"required":["origins","effectiveOrigins"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_partner_api_customers_by_externalId_embed_origins","tags":["partner-api"],"summary":"Cambiar los orígenes del embebido de un cliente","description":"`{ origins: string[] }` (máx. 20; `https://host[:puerto]` o `https://*.dominio.tld`; locales solo en sandbox) reemplaza la lista → `{ origins, effectiveOrigins }` · `422 validation_failed` · `409 customer_deleted` · `409 partner_inactive`.\n\nScopes: `partner:connections:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"origins":{"maxItems":60,"type":"array","items":{"type":"string","minLength":1,"maxLength":270}}},"required":["origins"]}}}},"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"origins":{"type":"array","items":{"type":"string"}},"effectiveOrigins":{"type":"array","items":{"type":"string"}}},"required":["origins","effectiveOrigins"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/sso":{"post":{"operationId":"post_partner_api_customers_by_externalId_sso","tags":["partner-api"],"summary":"Enlace de entrada con un clic para un cliente","description":"Entrada con un clic. `{ email, next?, name?, role?: 'admin' | 'agent' }` → `{ url: 'https://<host del revendedor>/api/auth/handoff?code=hs_…', expiresAt, expiresInSeconds: 60, user: { id, email, created } }`. El SaaS redirige al usuario a `url` y aterriza logueado en esa organización. Solo para miembros de ESA organización o usuarios creados por este revendedor (`403 sso_user_not_allowed`); `409 customer_deleted` · `409 organization_suspended` · `403 account_disabled` · `429` (600/min por revendedor). Sin Idempotency-Key (código de un uso).\n\nScopes: `partner:customers:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string","maxLength":254,"format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"},"next":{"type":"string","maxLength":500,"pattern":"^\\/(?!\\/)[^\\s\\\\]*$"},"name":{"type":"string","minLength":1,"maxLength":120},"role":{"default":"agent","type":"string","enum":["admin","agent"]}},"required":["email"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","description":"Enlace de entrada (un uso)."},"expiresAt":{"type":"string","format":"date-time"},"expiresInSeconds":{"type":"integer"},"user":{"type":"object","properties":{"id":{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},"email":{"type":"string"},"created":{"type":"boolean"}},"required":["id","email","created"]}},"required":["url","expiresAt","expiresInSeconds","user"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/customers/{externalId}/subscription":{"post":{"operationId":"post_partner_api_customers_by_externalId_subscription","tags":["partner-api"],"summary":"Informar el estado del plan de un cliente","description":"Estado del plan según el SaaS. `{ status: 'active' | 'past_due' | 'suspended' | 'canceled', connections?, graceUntil?, reason? }` → `{ customer, changed }`. `active` da acceso y cupo (y restaura una baja lógica); `past_due` deja acceso con aviso hasta `graceUntil` (vencido = suspendido); `suspended`/`canceled` bloquean y pausan las conexiones. Idempotente. `409 customer_deleted` (dado de baja y no se pide `active`) · `409 partner_inactive`.\n\nScopes: `partner:customers:write`.","parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"Id del cliente en tu sistema (el `externalId` con que lo diste de alta)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["active","past_due","suspended","canceled"]},"connections":{"anyOf":[{"type":"integer","minimum":0,"maximum":10000},{"type":"null"}]},"graceUntil":{"anyOf":[{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"},{"type":"null"}]},"reason":{"anyOf":[{"type":"string","maxLength":500},{"type":"null"}]}},"required":["status"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/PartnerCustomer"},"changed":{"description":"Ausente si el cliente se restauró.","type":"boolean"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/embed":{"get":{"operationId":"get_partner_api_embed","tags":["partner-api"],"summary":"Ajustes del embebido del revendedor","description":"Motores que el embebido del revendedor ofrece a sus clientes (lo mismo que las casillas de Partner → Integración → Embedded): `GET` → `{ embed: { engines } }` · `PUT { engines: ['qr'] | ['waba'] | ['qr', 'waba'] }`. Cada cliente puede acotarlos (`embed.engines` del cliente) y cada ventana también (`engines` de `embed-sessions`).\n\nScopes: `partner:customers:read`.","security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"embed":{"type":"object","properties":{"engines":{"type":"array","items":{"type":"string","enum":["qr","waba"]}}},"required":["engines"]}},"required":["embed"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_partner_api_embed","tags":["partner-api"],"summary":"Cambiar los ajustes del embebido","description":"Scopes: `partner:connections:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"engines":{"minItems":1,"maxItems":2,"type":"array","items":{"type":"string","enum":["qr","waba"]}}},"required":["engines"]}}}},"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"embed":{"type":"object","properties":{"engines":{"type":"array","items":{"type":"string","enum":["qr","waba"]}}},"required":["engines"]}},"required":["embed"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/embed/origins":{"get":{"operationId":"get_partner_api_embed_origins","tags":["partner-api"],"summary":"Orígenes permitidos del embebido","description":"Orígenes del embebido del revendedor por API (los mismos que el panel Partner → Integración → Embedded) → `{ origins, effectiveOrigins }`. `409 embed_not_available` (no interno).\n\nScopes: `partner:connections:read`.","security":[{"apiKey":["partner:connections:read"]},{"partnerToken":["partner:connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"origins":{"type":"array","items":{"type":"string"}},"effectiveOrigins":{"type":"array","items":{"type":"string"}}},"required":["origins","effectiveOrigins"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_partner_api_embed_origins","tags":["partner-api"],"summary":"Cambiar los orígenes permitidos del embebido","description":"`{ origins: string[] }` (máx. 50) reemplaza la lista → `{ origins, effectiveOrigins }` · `422 validation_failed` (origen inválido, o `active` sin ningún origen https) · `409 partner_inactive`.\n\nScopes: `partner:connections:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"origins":{"maxItems":60,"type":"array","items":{"type":"string","minLength":1,"maxLength":270}}},"required":["origins"]}}}},"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"origins":{"type":"array","items":{"type":"string"}},"effectiveOrigins":{"type":"array","items":{"type":"string"}}},"required":["origins","effectiveOrigins"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/api/subscription-events":{"post":{"operationId":"post_partner_api_subscription_events","tags":["partner-api"],"summary":"Enviar un lote de eventos de suscripción","description":"Sin Idempotency-Key: la idempotencia es por evento.\n\nScopes: `partner:customers:write`.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"events":{"minItems":1,"maxItems":50,"type":"array","items":{"type":"object","properties":{"eventId":{"type":"string","minLength":8,"maxLength":128},"externalId":{"type":"string","minLength":1,"maxLength":128,"pattern":"^[\\x21-\\x7e]+$"},"status":{"type":"string","enum":["active","past_due","suspended","canceled"]},"connections":{"anyOf":[{"type":"integer","minimum":0,"maximum":10000},{"type":"null"}]},"graceUntil":{"anyOf":[{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"},{"type":"null"}]},"reason":{"anyOf":[{"type":"string","maxLength":500},{"type":"null"}]},"occurredAt":{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"}},"required":["eventId","externalId","status","occurredAt"]}}},"required":["events"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"received":{"type":"integer"},"applied":{"type":"integer"},"ignored":{"type":"integer"},"results":{"type":"array","items":{"type":"object","properties":{"eventId":{"type":"string"},"externalId":{"type":"string"},"outcome":{"type":"string","enum":["applied","duplicate","stale","ignored"]},"reason":{"type":"string"}},"required":["eventId","externalId","outcome"]}}},"required":["received","applied","ignored","results"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/capacity":{"get":{"operationId":"get_partner_capacity","tags":["partner"],"summary":"Capacidad del revendedor","description":"Scopes: `partner:read`.","security":[{"apiKey":["partner:read"]},{"partnerToken":["partner:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"partnerActive":{"type":"boolean"},"partnerType":{"type":"string","enum":["internal","external"]},"internalCapacity":{"anyOf":[{"type":"object","properties":{"unlimited":{"type":"boolean"},"cap":{"anyOf":[{"type":"integer"},{"type":"null"}]},"used":{"type":"integer"},"available":{"anyOf":[{"type":"integer"},{"type":"null"}]}},"required":["unlimited","cap","used","available"]},{"type":"null"}],"description":"Solo revendedores internos (sin bolsa): conexiones usadas y tope; null en los demás."},"pools":{"type":"array","items":{"$ref":"#/components/schemas/CapacityPool"}},"features":{"type":"array","items":{"type":"object","properties":{"feature":{"type":"string"},"enabled":{"type":"boolean"},"maxQuantity":{"anyOf":[{"type":"integer"},{"type":"null"}]}},"required":["feature","enabled","maxQuantity"]}}},"required":["partnerActive","partnerType","internalCapacity","pools","features"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers":{"get":{"operationId":"get_partner_customers","tags":["partner"],"summary":"Listar clientes","description":"Scopes: `partner:customers:read`.","parameters":[{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["active","suspended","closed"]}},{"name":"externalId","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":128,"pattern":"^[\\x21-\\x7e]+$"}},{"name":"q","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":120}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":100}}],"security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ResellerCustomer"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_customers","tags":["partner"],"summary":"Dar de alta un cliente","description":"Alta de cliente: idempotente por Idempotency-Key (obligatoria) y por externalId (200 con el existente). Con `allocation`, alta y reserva de capacidad en la misma transacción.\n\nScopes: `partner:customers:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":120},"country":{"type":"string","minLength":2,"maxLength":2},"timezone":{"type":"string","minLength":3,"maxLength":64},"externalId":{"type":"string","minLength":1,"maxLength":128,"pattern":"^[\\x21-\\x7e]+$"},"isHouseAccount":{"type":"boolean"},"allocation":{"type":"object","properties":{"planId":{"type":"string","minLength":5,"maxLength":64},"quantity":{"type":"integer","minimum":1,"maximum":100000},"trial":{"type":"boolean"},"reason":{"type":"string","maxLength":500}}}},"required":["name"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK. `201` si se creó; `200` con el existente si ya había uno con ese `externalId`.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/ResellerCustomer"},"created":{"type":"boolean"}},"required":["customer","created"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}":{"get":{"operationId":"get_partner_customers_by_id","tags":["partner"],"summary":"Ver un cliente","description":"Scopes: `partner:customers:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/ResellerCustomerDetail"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_partner_customers_by_id","tags":["partner"],"summary":"Editar un cliente","description":"Scopes: `partner:customers:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":120},"country":{"type":"string","minLength":2,"maxLength":2},"timezone":{"type":"string","minLength":3,"maxLength":64},"externalId":{"anyOf":[{"type":"string","minLength":1,"maxLength":128,"pattern":"^[\\x21-\\x7e]+$"},{"type":"null"}]},"historyImport":{"type":"boolean"}}}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/ResellerCustomer"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/agent-credits":{"get":{"operationId":"get_partner_customers_by_id_agent_credits","tags":["partner"],"summary":"Créditos de IA de un cliente","description":"Créditos de IA de un cliente del revendedor. `{id}` = `org_…` o su `externalId` (de otro revendedor → 404). - `GET` → `{ customer: { id, externalId, balance, usedThisMonth, lots, ledger } }`. - `POST { credits }` → `{ customer: { id, externalId, balance }, partner: { balance } }`: asigna de la billetera del revendedor (por orden de vencimiento; el cliente conserva el vencimiento) · `422 insufficient_credits`. Exige `Idempotency-Key`. API de partners: `partner:credits:write` (alias `credits:write`).\n\nScopes: `partner:customers:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["partner:customers:read"]},{"partnerToken":["partner:customers:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"externalId":{"type":["string","null"]},"balance":{"type":"integer"},"usedThisMonth":{"type":"integer"},"lots":{"type":"array","items":{"$ref":"#/components/schemas/CreditLot"}},"ledger":{"type":"array","items":{"$ref":"#/components/schemas/CreditLedgerEntry"}}},"required":["id","externalId","balance","usedThisMonth","lots","ledger"]}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_customers_by_id_agent_credits","tags":["partner"],"summary":"Asignar créditos de IA a un cliente","description":"Scopes: `partner:credits:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"credits":{"type":"integer","minimum":1,"maximum":10000000}},"required":["credits"]}}}},"security":[{"apiKey":["partner:credits:write"]},{"partnerToken":["partner:credits:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"externalId":{"type":["string","null"]},"balance":{"type":"integer"}},"required":["id","externalId","balance"]},"partner":{"type":"object","properties":{"balance":{"type":"integer","description":"Saldo que te queda."}},"required":["balance"]}},"required":["customer","partner"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/allocation":{"delete":{"operationId":"delete_partner_customers_by_id_allocation","tags":["partner"],"summary":"Liberar la capacidad de un cliente","description":"Libera toda la capacidad del cliente (sin conexiones en uso). Exige Idempotency-Key.\n\nScopes: `partner:allocations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:allocations:write"]},{"partnerToken":["partner:allocations:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"allocation":{"anyOf":[{"$ref":"#/components/schemas/CapacityAllocation"},{"type":"null"}],"description":"Null si no tenía asignación."},"pool":{"anyOf":[{"$ref":"#/components/schemas/CapacityPool"},{"type":"null"}]}},"required":["allocation","pool"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"put":{"operationId":"put_partner_customers_by_id_allocation","tags":["partner"],"summary":"Asignar capacidad a un cliente","description":"Asigna o cambia la capacidad del cliente (plan del partner o cantidad) con reserva atómica de la bolsa. 201 al crear la asignación, 200 al cambiarla; 409 partner_capacity_exceeded o allocation_in_use. Exige Idempotency-Key.\n\nScopes: `partner:allocations:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"planId":{"type":"string","minLength":5,"maxLength":64},"quantity":{"type":"integer","minimum":1,"maximum":100000},"trial":{"type":"boolean"},"reason":{"type":"string","maxLength":500}}}}}},"security":[{"apiKey":["partner:allocations:write"]},{"partnerToken":["partner:allocations:write"]}],"responses":{"200":{"description":"OK. `201` al crear la asignación; `200` al cambiarla.","content":{"application/json":{"schema":{"type":"object","properties":{"allocation":{"$ref":"#/components/schemas/CapacityAllocation"},"pool":{"$ref":"#/components/schemas/CapacityPool"}},"required":["allocation","pool"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/connections":{"get":{"operationId":"get_partner_customers_by_id_connections","tags":["partner"],"summary":"Conexiones de un cliente","description":"Conexiones de un cliente, con las mismas reglas que /v1/connections en su tenant.\n\nScopes: `partner:connections:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["partner:connections:read"]},{"partnerToken":["partner:connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}}},"required":["connections"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_customers_by_id_connections","tags":["partner"],"summary":"Crear una conexión para un cliente","description":"Crea una conexión en el cliente (consume su asignación). Exige Idempotency-Key.\n\nScopes: `partner:connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"label":{"type":"string","minLength":1,"maxLength":60}},"required":["label"]}}}},"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/connections/{connectionId}":{"delete":{"operationId":"delete_partner_customers_by_id_connections_by_connectionId","tags":["partner"],"summary":"Eliminar una conexión de un cliente","description":"Scopes: `partner:connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_partner_customers_by_id_connections_by_connectionId","tags":["partner"],"summary":"Ver una conexión de un cliente","description":"Scopes: `partner:connections:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."}],"security":[{"apiKey":["partner:connections:read"]},{"partnerToken":["partner:connections:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/connections/{connectionId}/logout":{"post":{"operationId":"post_partner_customers_by_id_connections_by_connectionId_logout","tags":["partner"],"summary":"Cerrar la sesión de WhatsApp de una conexión de un cliente","description":"Scopes: `partner:connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"connection":{"$ref":"#/components/schemas/Connection"}},"required":["connection"]},"example":{"connection":{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/connections/{connectionId}/qr":{"get":{"operationId":"get_partner_customers_by_id_connections_by_connectionId_qr","tags":["partner"],"summary":"Código QR de una conexión de un cliente","description":"QR para vincular el número del cliente.\n\nScopes: `partner:connections:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"connectionId","in":"path","required":true,"schema":{"type":"string"},"description":"Id público de la conexión (`conn_…`)."}],"security":[{"apiKey":["partner:connections:write"]},{"partnerToken":["partner:connections:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConnectionQr"}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/owner-invitation":{"post":{"operationId":"post_partner_customers_by_id_owner_invitation","tags":["partner"],"summary":"Invitar al owner de un cliente","description":"Invita por email al owner del cliente (el partner no es miembro de sus clientes).\n\nScopes: `partner:customers:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string","maxLength":254,"format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"}},"required":["email"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"invitation":{"$ref":"#/components/schemas/Invitation"}},"required":["invitation"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/reactivate":{"post":{"operationId":"post_partner_customers_by_id_reactivate","tags":["partner"],"summary":"Reactivar un cliente","description":"Reactiva al cliente y levanta solo las pausas `partner_suspended` (hay que reescanear el QR).\n\nScopes: `partner:customers:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/ResellerCustomerDetail"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/subscription-state":{"post":{"operationId":"post_partner_customers_by_id_subscription_state","tags":["partner"],"summary":"Cambiar el estado del plan de un cliente","description":"«Suspender/Reactivar acceso» desde el panel del revendedor, con la MISMA máquina de estados que la API de partners. `{ status: 'active' | 'suspended', reason? }` → `200 { customer }` (con `customer.plan`). Solo en `included`/`external`: con `partner_paypal` → `409 billing_mode_mismatch`. `403` si la suspendió WAQR · `409 partner_inactive` al reactivar con el revendedor inactivo. Idempotente.\n\nScopes: `partner:customers:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["active","suspended"]},"reason":{"type":"string","maxLength":500}},"required":["status"]}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/ResellerCustomerDetail"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/suspend":{"post":{"operationId":"post_partner_customers_by_id_suspend","tags":["partner"],"summary":"Suspender un cliente","description":"Suspende al cliente: lectura permitida, conexiones pausadas (`partner_suspended`). Idempotente.\n\nScopes: `partner:customers:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"reason":{"type":"string","maxLength":500}}}}}},"security":[{"apiKey":["partner:customers:write"]},{"partnerToken":["partner:customers:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/ResellerCustomerDetail"}},"required":["customer"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/customers/{id}/usage":{"get":{"operationId":"get_partner_customers_by_id_usage","tags":["partner"],"summary":"Uso de un cliente","description":"Scopes: `partner:usage:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["partner:usage:read"]},{"partnerToken":["partner:usage:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"customerId":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"resources":{"type":"array","items":{"type":"object","properties":{"resource":{"type":"string","enum":["whatsapp_connection"]},"used":{"type":"integer"},"limit":{"type":"integer"},"allocated":{"type":"integer"},"unlimited":{"type":"boolean","const":true}},"required":["resource","used","limit","allocated"]}}},"required":["customerId","resources"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/fees":{"get":{"operationId":"get_partner_fees","tags":["partner"],"summary":"Cuotas del revendedor","description":"Cuotas mensuales del revendedor con WAQR (un importe por cada conexión de sus clientes, cobradas por adelantado). Devuelve la tarifa (`plan`, null si el revendedor no paga cuota), si el uso de sus clientes está pausado por una cuota vencida (`blocked`) y las cuotas de los últimos 36 meses con su importe, número de conexiones, vencimiento (`dueAt`, día 1) y corte (`cutAt`, día 2).\n\nScopes: `partner:fees:read`.","security":[{"apiKey":["partner:fees:read"]},{"partnerToken":["partner:fees:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"plan":{"anyOf":[{"type":"object","properties":{"unitCents":{"type":"integer","description":"Importe por conexión y mes."},"currency":{"type":"string"},"billing":{"type":"string","enum":["monthly_in_advance","off"]},"startsOn":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","description":"Primer mes que se cobra."},"timeZone":{"type":"string"}},"required":["unitCents","currency","billing","startsOn","timeZone"]},{"type":"null"}],"description":"Tu tarifa; null si no pagas cuota."},"blocked":{"type":"boolean","description":"Cuota vencida: el uso de tus clientes está pausado."},"canPayOnline":{"type":"boolean"},"fees":{"type":"array","items":{"$ref":"#/components/schemas/PartnerFee"}}},"required":["plan","blocked","canPayOnline","fees"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/fees/{id}":{"get":{"operationId":"get_partner_fees_by_id","tags":["partner"],"summary":"Ver una cuota del revendedor","description":"Una cuota con sus líneas: por cada conexión de cada cliente, el tramo cobrado (`month` = mes completo; `prorate` = días de un alta reciente), sus días y su importe. El cliente va con su `externalId` (tu id) y la conexión con su etiqueta y número.\n\nScopes: `partner:fees:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["partner:fees:read"]},{"partnerToken":["partner:fees:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"fee":{"type":"object","properties":{"id":{"type":"string","pattern":"^fee_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`fee_…`)."},"period":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","description":"Primer día del mes que cubre la cuota (`YYYY-MM-DD`)."},"status":{"type":"string","enum":["pending","paid","void"],"description":"`pending` hasta el pago; con el corte vencido, el uso de tus clientes queda pausado."},"amountCents":{"type":"integer","description":"Importe en la unidad menor de la moneda."},"currency":{"type":"string"},"connections":{"type":"integer","description":"Conexiones cobradas en esta cuota."},"dueAt":{"anyOf":[{"type":"string","format":"date-time","description":"Vencimiento (día 1 del mes, en tu zona horaria)."},{"type":"null"}]},"cutAt":{"anyOf":[{"type":"string","format":"date-time","description":"Corte (día 2): sin pagar, el servicio de tus clientes se pausa."},{"type":"null"}]},"paidAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"paidVia":{"anyOf":[{"type":"string","enum":["paypal","manual"]},{"type":"null"}]},"createdAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"items":{"type":"array","items":{"$ref":"#/components/schemas/PartnerFeeItem"}}},"required":["id","period","status","amountCents","currency","connections","dueAt","cutAt","paidAt","paidVia","createdAt","items"]}},"required":["fee"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/fees/{id}/checkout":{"post":{"operationId":"post_partner_fees_by_id_checkout","tags":["partner"],"summary":"Pagar una cuota con PayPal","description":"Inicia el pago con PayPal de una cuota pendiente del revendedor → `201 { approvalUrl, orderId }`. Redirige a quien paga a `approvalUrl`. Desde tu propio panel, manda `returnUrl` (https): PayPal vuelve allí con `?token=<orderId>` y, al volver, confirma el pago con `POST /v1/partner/fees/checkout/return`. `cancelUrl` (opcional, por defecto la misma) es adonde vuelve si cancela. Sin `returnUrl`, vuelve al panel de WAQR. `409 partner_fee_not_payable` si la cuota ya está pagada o anulada.\n\nScopes: `partner:fees:pay`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"returnUrl":{"type":"string","maxLength":2048,"format":"uri"},"cancelUrl":{"type":"string","maxLength":2048,"format":"uri"}},"additionalProperties":false}}}},"security":[{"apiKey":["partner:fees:pay"]},{"partnerToken":["partner:fees:pay"]}],"responses":{"201":{"description":"Creado. `201`: lleva a quien paga a `approvalUrl` (PayPal).","content":{"application/json":{"schema":{"type":"object","properties":{"approvalUrl":{"type":"string","description":"Página de PayPal donde se aprueba el pago."},"orderId":{"type":"string","description":"Pedido de PayPal; vuelve como `token` en tu `returnUrl`."}},"required":["approvalUrl","orderId"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/fees/checkout/return":{"post":{"operationId":"post_partner_fees_checkout_return","tags":["partner"],"summary":"Confirmar el pago de una cuota","description":"Confirma el pago de una cuota al volver de PayPal: `orderId` es el `token` que PayPal añade a tu `returnUrl`. Cobra el pedido (idempotente: repetirlo no cobra dos veces), marca la cuota pagada y, si el servicio estaba pausado por la cuota vencida, vuelve al instante. `409 order_not_approved` si quien paga no aprobó el pago en PayPal; `409 payment_pending` si PayPal aún no lo completó.\n\nScopes: `partner:fees:pay`.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"orderId":{"type":"string","minLength":1,"maxLength":64}},"required":["orderId"],"additionalProperties":false}}}},"security":[{"apiKey":["partner:fees:pay"]},{"partnerToken":["partner:fees:pay"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"fee":{"$ref":"#/components/schemas/PartnerFee"},"status":{"type":"string","const":"paid"}},"required":["fee","status"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/ledger":{"get":{"operationId":"get_partner_ledger","tags":["partner"],"summary":"Movimientos de capacidad","description":"Libro de movimientos de capacidad (solo lectura, cursor opaco).\n\nScopes: `partner:read`.","parameters":[{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"limit","in":"query","required":false,"schema":{"default":50,"type":"integer","minimum":1,"maximum":200}}],"security":[{"apiKey":["partner:read"]},{"partnerToken":["partner:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/CapacityLedgerEntry"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/plans":{"get":{"operationId":"get_partner_plans","tags":["partner"],"summary":"Listar planes del revendedor","description":"Scopes: `partner:plans:read`.","parameters":[{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["draft","active","archived"]}}],"security":[{"apiKey":["partner:plans:read"]},{"partnerToken":["partner:plans:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/PartnerPlan"}}},"required":["data"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_partner_plans","tags":["partner"],"summary":"Crear un plan","description":"Crear un plan no reserva capacidad. Exige Idempotency-Key.\n\nScopes: `partner:plans:write`.","parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"string","pattern":"^[a-z0-9][a-z0-9_-]{0,47}$"},"name":{"type":"string","minLength":1,"maxLength":120},"description":{"type":"string","maxLength":1000},"status":{"default":"active","type":"string","enum":["draft","active","archived"]},"visibility":{"default":"listed","type":"string","enum":["listed","hidden"]},"price":{"anyOf":[{"type":"object","properties":{"amountCents":{"type":"integer","minimum":0,"maximum":1000000000},"currency":{"type":"string","pattern":"^[A-Za-z]{3}$"},"interval":{"type":"string","enum":["month","year"]}},"required":["amountCents","currency","interval"]},{"type":"null"}]},"trialDays":{"default":0,"type":"integer","minimum":0,"maximum":365},"entitlements":{"minItems":1,"maxItems":20,"type":"array","items":{"type":"object","properties":{"feature":{"type":"string","pattern":"^[a-z][a-z0-9_]{1,63}$"},"quantity":{"type":"integer","minimum":0,"maximum":1000000},"enabled":{"type":"boolean"}},"required":["feature"]}}},"required":["code","name","entitlements"]}}}},"security":[{"apiKey":["partner:plans:write"]},{"partnerToken":["partner:plans:write"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"plan":{"$ref":"#/components/schemas/PartnerPlan"}},"required":["plan"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/plans/{id}":{"get":{"operationId":"get_partner_plans_by_id","tags":["partner"],"summary":"Ver un plan","description":"Scopes: `partner:plans:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["partner:plans:read"]},{"partnerToken":["partner:plans:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"plan":{"$ref":"#/components/schemas/PartnerPlan"}},"required":["plan"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_partner_plans_by_id","tags":["partner"],"summary":"Editar o archivar un plan","description":"Editar (o archivar con status) un plan; no cambia asignaciones ya hechas.\n\nScopes: `partner:plans:write`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":120},"description":{"anyOf":[{"type":"string","maxLength":1000},{"type":"null"}]},"status":{"type":"string","enum":["draft","active","archived"]},"visibility":{"type":"string","enum":["listed","hidden"]},"price":{"anyOf":[{"type":"object","properties":{"amountCents":{"type":"integer","minimum":0,"maximum":1000000000},"currency":{"type":"string","pattern":"^[A-Za-z]{3}$"},"interval":{"type":"string","enum":["month","year"]}},"required":["amountCents","currency","interval"]},{"type":"null"}]},"trialDays":{"type":"integer","minimum":0,"maximum":365},"entitlements":{"minItems":1,"maxItems":20,"type":"array","items":{"type":"object","properties":{"feature":{"type":"string","pattern":"^[a-z][a-z0-9_]{1,63}$"},"quantity":{"type":"integer","minimum":0,"maximum":1000000},"enabled":{"type":"boolean"}},"required":["feature"]}}}}}}},"security":[{"apiKey":["partner:plans:write"]},{"partnerToken":["partner:plans:write"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"plan":{"$ref":"#/components/schemas/PartnerPlan"}},"required":["plan"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/partner/usage":{"get":{"operationId":"get_partner_usage","tags":["partner"],"summary":"Uso del revendedor","description":"Scopes: `partner:usage:read`.","security":[{"apiKey":["partner:usage:read"]},{"partnerToken":["partner:usage:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"totals":{"type":"object","properties":{"customers":{"type":"integer"},"connectionsUsed":{"type":"integer"},"connectionsAllocated":{"type":"integer"}},"required":["customers","connectionsUsed","connectionsAllocated"]},"customers":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"name":{"type":"string"},"status":{"type":"string","enum":["active","suspended","closed"]},"connections":{"type":"object","properties":{"used":{"type":"integer"},"limit":{"type":"integer"},"unlimited":{"type":"boolean","const":true}},"required":["used","limit"]}},"required":["id","name","status","connections"]}}},"required":["totals","customers"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/search":{"get":{"operationId":"get_search","tags":["search"],"summary":"Buscar en conversaciones, mensajes y contactos","description":"Búsqueda: chats (vista de la lista) cuyo contacto o grupo coincide por fragmento de nombre/asunto sin tildes o por dígitos del número, contactos sin chat, grupos, mensajes (FTS con prefijo) y sus conversaciones.\n\nScopes: `messages:read`.","parameters":[{"name":"q","in":"query","required":true,"schema":{"type":"string","minLength":2,"maxLength":200}},{"name":"connectionId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"limit","in":"query","required":false,"schema":{"default":20,"type":"integer","minimum":1,"maximum":50}}],"security":[{"apiKey":["messages:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"messages":{"type":"array","items":{"$ref":"#/components/schemas/Message"}},"contacts":{"type":"array","items":{"$ref":"#/components/schemas/ContactSummary"}},"groups":{"type":"array","items":{"$ref":"#/components/schemas/Group"}},"chats":{"type":"array","items":{"$ref":"#/components/schemas/Conversation"},"description":"Conversaciones cuyo contacto o grupo coincide."},"messageConversations":{"type":"array","items":{"$ref":"#/components/schemas/Conversation"},"description":"Conversaciones de los mensajes encontrados."}},"required":["messages","contacts","groups","chats","messageConversations"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/deliveries":{"get":{"operationId":"get_webhooks_deliveries","tags":["webhooks"],"summary":"Registro de entregas de webhooks","description":"Registro de entregas (más recientes primero, cursor opaco): estado, código, duración y error.\n\nScopes: `webhooks:read`, `partner:webhooks:read`.","parameters":[{"name":"endpointId","in":"query","required":false,"schema":{"type":"string","minLength":5,"maxLength":64}},{"name":"state","in":"query","required":false,"schema":{"type":"string","enum":["pending","delivering","succeeded","failed","exhausted","canceled"]}},{"name":"eventType","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":64}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100}}],"security":[{"apiKey":["webhooks:read"]},{"apiKey":["partner:webhooks:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/WebhookDelivery"}},"nextCursor":{"description":"Cursor de la página siguiente (`?cursor=`); null en la última.","type":["string","null"]}},"required":["data","nextCursor"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/deliveries/{id}":{"get":{"operationId":"get_webhooks_deliveries_by_id","tags":["webhooks"],"summary":"Ver una entrega y sus intentos","description":"Detalle de una entrega con sus últimos intentos (sin cuerpos ni cabeceras de respuesta).\n\nScopes: `webhooks:read`, `partner:webhooks:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["webhooks:read"]},{"apiKey":["partner:webhooks:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"delivery":{"$ref":"#/components/schemas/WebhookDeliveryDetail"}},"required":["delivery"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/deliveries/{id}/replay":{"post":{"operationId":"post_webhooks_deliveries_by_id_replay","tags":["webhooks"],"summary":"Reenviar una entrega","description":"Scopes: `webhooks:manage`, `partner:webhooks:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["webhooks:manage"]},{"apiKey":["partner:webhooks:manage"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"delivery":{"$ref":"#/components/schemas/WebhookDelivery"}},"required":["delivery"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/endpoints":{"get":{"operationId":"get_webhooks_endpoints","tags":["webhooks"],"summary":"Listar endpoints de webhook","description":"Scopes: `webhooks:read`, `partner:webhooks:read`.","security":[{"apiKey":["webhooks:read"]},{"apiKey":["partner:webhooks:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"endpoints":{"type":"array","items":{"$ref":"#/components/schemas/WebhookEndpoint"}}},"required":["endpoints"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"post":{"operationId":"post_webhooks_endpoints","tags":["webhooks"],"summary":"Crear un endpoint de webhook","description":"Alta de endpoint: devuelve el secreto `whsec_` UNA vez (`secret`). Sin idempotencia guardada (la respuesta lleva el secreto); un reintento con la misma URL es 409 `conflict`.\n\nScopes: `webhooks:manage`, `partner:webhooks:manage`.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","minLength":1,"maxLength":2048},"events":{"minItems":1,"maxItems":50,"type":"array","items":{"type":"string","minLength":1,"maxLength":64}},"description":{"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]},"source":{"anyOf":[{"type":"string","enum":["n8n","zapier","make"]},{"type":"null"}]}},"required":["url","events"]}}}},"security":[{"apiKey":["webhooks:manage"]},{"apiKey":["partner:webhooks:manage"]}],"responses":{"201":{"description":"Creado.","content":{"application/json":{"schema":{"type":"object","properties":{"endpoint":{"$ref":"#/components/schemas/WebhookEndpoint"},"secret":{"type":"string","description":"Secreto de firma `whsec_…`: se muestra solo esta vez."}},"required":["endpoint","secret"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/endpoints/{id}":{"delete":{"operationId":"delete_webhooks_endpoints_by_id","tags":["webhooks"],"summary":"Eliminar un endpoint de webhook","description":"Scopes: `webhooks:manage`, `partner:webhooks:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["webhooks:manage"]},{"apiKey":["partner:webhooks:manage"]}],"responses":{"204":{"description":"Hecho, sin contenido."},"default":{"$ref":"#/components/responses/Problem"}}},"get":{"operationId":"get_webhooks_endpoints_by_id","tags":["webhooks"],"summary":"Ver un endpoint de webhook","description":"Scopes: `webhooks:read`, `partner:webhooks:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["webhooks:read"]},{"apiKey":["partner:webhooks:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"endpoint":{"$ref":"#/components/schemas/WebhookEndpoint"}},"required":["endpoint"]}}}},"default":{"$ref":"#/components/responses/Problem"}}},"patch":{"operationId":"patch_webhooks_endpoints_by_id","tags":["webhooks"],"summary":"Editar o reactivar un endpoint de webhook","description":"Cambia URL, eventos o descripción; `status: active` reactiva un endpoint desactivado.\n\nScopes: `webhooks:manage`, `partner:webhooks:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","minLength":1,"maxLength":2048},"events":{"minItems":1,"maxItems":50,"type":"array","items":{"type":"string","minLength":1,"maxLength":64}},"description":{"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]},"source":{"anyOf":[{"type":"string","enum":["n8n","zapier","make"]},{"type":"null"}]},"status":{"type":"string","enum":["active","disabled"]}}}}}},"security":[{"apiKey":["webhooks:manage"]},{"apiKey":["partner:webhooks:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"endpoint":{"$ref":"#/components/schemas/WebhookEndpoint"}},"required":["endpoint"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/endpoints/{id}/rotate-secret":{"post":{"operationId":"post_webhooks_endpoints_by_id_rotate_secret","tags":["webhooks"],"summary":"Rotar el secreto de firma","description":"Secreto nuevo (mostrado una vez); el anterior sigue firmando durante el solape configurado.\n\nScopes: `webhooks:manage`, `partner:webhooks:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."}],"security":[{"apiKey":["webhooks:manage"]},{"apiKey":["partner:webhooks:manage"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"endpoint":{"$ref":"#/components/schemas/WebhookEndpoint"},"secret":{"type":"string","description":"Secreto de firma `whsec_…`: se muestra solo esta vez."},"previousSecretExpiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"description":"Hasta cuándo sigue valiendo el secreto anterior."}},"required":["endpoint","secret","previousSecretExpiresAt"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/endpoints/{id}/test":{"post":{"operationId":"post_webhooks_endpoints_by_id_test","tags":["webhooks"],"summary":"Enviar un evento de prueba","description":"Scopes: `webhooks:manage`, `partner:webhooks:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"},"description":"Id público del recurso (con prefijo: `conn_…`, `conv_…`, `msg_…`, `ct_…`…)."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","minLength":1,"maxLength":255},"description":"Clave única por operación (p. ej. un UUID). Repetir la petición con la misma clave devuelve la misma respuesta sin repetir el efecto durante 24 h."}],"security":[{"apiKey":["webhooks:manage"]},{"apiKey":["partner:webhooks:manage"]}],"responses":{"202":{"description":"Aceptado: se procesa en segundo plano.","content":{"application/json":{"schema":{"type":"object","properties":{"delivery":{"$ref":"#/components/schemas/WebhookDelivery"}},"required":["delivery"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/webhooks/event-types":{"get":{"operationId":"get_webhooks_event_types","tags":["webhooks"],"summary":"Catálogo de eventos de webhook","description":"Catálogo de tipos de evento a los que se puede suscribir un endpoint (más `*` = todos).\n\nScopes: `webhooks:read`, `partner:webhooks:read`.","security":[{"apiKey":["webhooks:read"]},{"apiKey":["partner:webhooks:read"]}],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"object","properties":{"eventTypes":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string"},"description":{"type":"string"}},"required":["type","description"]}}},"required":["eventTypes"]}}}},"default":{"$ref":"#/components/responses/Problem"}}}},"/v1/oauth/token":{"post":{"operationId":"post_oauth_token","tags":["partner-api"],"summary":"Token de acceso de partner (client credentials)","description":"El servidor de un revendedor se autentica con su `client_id` (`pcl_…`) y `client_secret` (`Authorization: Basic` o en el cuerpo) y recibe un token Bearer de 10 minutos para las rutas de partner. Errores también con el campo `error` de OAuth 2.0 (`invalid_client`, `invalid_request`, `unsupported_grant_type`, `invalid_scope`).","security":[],"requestBody":{"required":true,"content":{"application/x-www-form-urlencoded":{"schema":{"type":"object","required":["grant_type"],"properties":{"grant_type":{"const":"client_credentials"},"client_id":{"type":"string"},"client_secret":{"type":"string"},"scope":{"type":"string","description":"Scopes separados por espacios (opcional)."}}}}}},"responses":{"200":{"description":"Token emitido.","content":{"application/json":{"schema":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string"},"token_type":{"const":"Bearer"},"expires_in":{"type":"integer","example":600},"scope":{"type":"string"}}}}}},"default":{"$ref":"#/components/responses/Problem"}}}}},"webhooks":{"connection.created":{"post":{"operationId":"webhook_connection_created","summary":"Se creó una conexión de WhatsApp","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.created"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.updated":{"post":{"operationId":"webhook_connection_updated","summary":"Se cambió el nombre de una conexión o, en WhatsApp oficial, el estado de la cuenta (`waba`: calidad, límite, nombre, revisión y `health` con `status` ok, limited, payment_issue o blocked; `metaEvent` con el aviso de Meta)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.connected":{"post":{"operationId":"webhook_connection_connected","summary":"La conexión quedó vinculada y conectada","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.connected"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.disconnected":{"post":{"operationId":"webhook_connection_disconnected","summary":"La conexión se desconectó, se cerró la sesión o se bloqueó (`status` y `reason`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.disconnected"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.qr_updated":{"post":{"operationId":"webhook_connection_qr_updated","summary":"Hay un QR nuevo que escanear (nunca incluye la imagen: pídelo con GET …/qr)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.qr_updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.deleted":{"post":{"operationId":"webhook_connection_deleted","summary":"Se borró una conexión","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.deleted"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.paused":{"post":{"operationId":"webhook_connection_paused","summary":"La conexión se pausó (prueba, cobertura o suspensión del partner)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.paused"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.resumed":{"post":{"operationId":"webhook_connection_resumed","summary":"La conexión volvió a estar disponible","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.resumed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"organization.updated":{"post":{"operationId":"webhook_organization_updated","summary":"Cambió el nombre, el país o la zona horaria (solo nombres de campo)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"organization.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"member.added":{"post":{"operationId":"webhook_member_added","summary":"Alguien se unió a la organización","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"member.added"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"member.role_changed":{"post":{"operationId":"webhook_member_role_changed","summary":"Cambió el rol de un miembro","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"member.role_changed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"member.removed":{"post":{"operationId":"webhook_member_removed","summary":"Un miembro salió o fue retirado","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"member.removed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"invitation.created":{"post":{"operationId":"webhook_invitation_created","summary":"Se envió una invitación","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"invitation.created"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"invitation.accepted":{"post":{"operationId":"webhook_invitation_accepted","summary":"Se aceptó una invitación","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"invitation.accepted"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"invitation.revoked":{"post":{"operationId":"webhook_invitation_revoked","summary":"Se revocó una invitación","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"invitation.revoked"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.customer.created":{"post":{"operationId":"webhook_partner_customer_created","summary":"El partner dio de alta un cliente (solo endpoints del partner)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.customer.created"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.customer.suspended":{"post":{"operationId":"webhook_partner_customer_suspended","summary":"El partner suspendió a un cliente","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.customer.suspended"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.customer.reactivated":{"post":{"operationId":"webhook_partner_customer_reactivated","summary":"El partner reactivó a un cliente","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.customer.reactivated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.customer.deleted":{"post":{"operationId":"webhook_partner_customer_deleted","summary":"El partner dio de baja a un cliente desde la API de partners (conexiones pausadas, datos conservados; solo endpoints del partner)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.customer.deleted"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.customer.updated":{"post":{"operationId":"webhook_partner_customer_updated","summary":"El partner cambió el nombre u otros datos de un cliente (`fields`; solo endpoints del partner)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.customer.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"message.received":{"post":{"operationId":"webhook_message_received","summary":"Llegó un mensaje (ids, `externalId` = id de WhatsApp, `quotedExternalId` del citado o reaccionado, tipo, `conversationType` y `text`: el texto o el pie de foto, vídeo o documento, hasta 4096 caracteres, o null; en grupo, `groupId` y `sender`; nunca la media)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"message.received"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"message.sent":{"post":{"operationId":"webhook_message_sent","summary":"Se envió un mensaje desde la conexión: desde WAQR cuando el motor lo acepta (`origin: waqr`) o desde el teléfono (`origin: device`); mismos campos que `message.received`, `text`, `externalId` y `quotedExternalId` incluidos","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"message.sent"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"message.failed":{"post":{"operationId":"webhook_message_failed","summary":"Un mensaje no salió (`reason`: `not_on_whatsapp`, `outcome_unknown`, `expired`, `waba_payment_issue`, `waba_account_locked`…); también cuando Meta avisa del fallo después de aceptarlo (`after: accepted`, `errorCode`); nunca se reintenta solo","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"message.failed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"message.status_updated":{"post":{"operationId":"webhook_message_status_updated","summary":"Cambió el estado de entrega de un mensaje enviado (`sent`, `delivered`, `read`, `played`, `failed`, con su `externalId` de WhatsApp; en grupos no hay recibos por participante). En WhatsApp oficial, `pricing` (y `message.pricing`) lleva el precio de Meta (`billable`, `category`, `pricingModel`, `type`), también en un recibo que no cambia el estado","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"message.status_updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"message.edited":{"post":{"operationId":"webhook_message_edited","summary":"Se editó un mensaje (solo ids: el texto nuevo se pide a la API)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"message.edited"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"message.deleted":{"post":{"operationId":"webhook_message_deleted","summary":"Se borró un mensaje para todos","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"message.deleted"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"conversation.created":{"post":{"operationId":"webhook_conversation_created","summary":"Se creó una conversación (1:1 o de grupo)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"conversation.created"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"contact.created":{"post":{"operationId":"webhook_contact_created","summary":"Se creó un contacto mínimo porque escribió o se le escribió (`createdVia`; nunca por pertenecer a un grupo)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"contact.created"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"contact.updated":{"post":{"operationId":"webhook_contact_updated","summary":"Cambió el nombre mostrado u otros datos de un contacto (solo nombres de campo)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"contact.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"contact.merged":{"post":{"operationId":"webhook_contact_merged","summary":"Dos contactos se fusionaron (`reason`: `pn_lid_pair` del protocolo o `manual`): `survivorId`, `mergedId` y, si es manual, `mergeId`","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"contact.merged"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"contact.unmerged":{"post":{"operationId":"webhook_contact_unmerged","summary":"Se revirtió una fusión manual: `survivorId`, `restoredId` (el contacto que vuelve) y `mergeId`","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"contact.unmerged"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"group.observed":{"post":{"operationId":"webhook_group_observed","summary":"Se vio un grupo por primera vez en una conexión (primer mensaje o evento)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"group.observed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"group.updated":{"post":{"operationId":"webhook_group_updated","summary":"El refresco de metadatos detectó un cambio (asunto, descripción, ajustes, foto); llega con retraso y sin autor","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"group.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"group.participant_added":{"post":{"operationId":"webhook_group_participant_added","summary":"Alguien entró en un grupo (sin crear contactos)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"group.participant_added"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"group.participant_removed":{"post":{"operationId":"webhook_group_participant_removed","summary":"Alguien salió de un grupo (`reason`: `removed` o `left`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"group.participant_removed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"group.participant_promoted":{"post":{"operationId":"webhook_group_participant_promoted","summary":"Un participante pasó a administrador","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"group.participant_promoted"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"group.participant_demoted":{"post":{"operationId":"webhook_group_participant_demoted","summary":"Un participante dejó de ser administrador","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"group.participant_demoted"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"media.ready":{"post":{"operationId":"webhook_media_ready","summary":"El adjunto de un mensaje ya está guardado (`attachmentId`, `messageId`, tipo, tamaño y sha256); se descarga con GET /v1/messages/{id}/attachments/{id} (URL firmada de corta vida)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"media.ready"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"template.updated":{"post":{"operationId":"webhook_template_updated","summary":"Meta cambió el estado o la categoría de una plantilla de WhatsApp oficial (`connectionId`, `name`, `language`, `status`, `category`, `previousCategory`, `reason`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"template.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"connection.usage_threshold_reached":{"post":{"operationId":"webhook_connection_usage_threshold_reached","summary":"Una conexión de WhatsApp oficial pasó su tope del mes (`metric`: `billable` o `cost`, `threshold`, `value`, `month`); una vez por tope y mes","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"connection.usage_threshold_reached"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"google_contacts.needs_reauth":{"post":{"operationId":"webhook_google_contacts_needs_reauth","summary":"La cuenta de Google Contacts dejó de autorizar a WAQR (revocada, caducada o sin el permiso): hay que volver a conectarla; los datos se conservan","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"google_contacts.needs_reauth"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"google_contacts.sync_completed":{"post":{"operationId":"webhook_google_contacts_sync_completed","summary":"Terminó una sincronización COMPLETA con Google Contacts (la primera o tras caducar el syncToken), con totales","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"google_contacts.sync_completed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"subscription.created":{"post":{"operationId":"webhook_subscription_created","summary":"La suscripción quedó aprobada y verificada con el proveedor (`status`: `trialing` o `active`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"subscription.created"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"subscription.updated":{"post":{"operationId":"webhook_subscription_updated","summary":"Cambió el estado, el periodo o la cantidad de la suscripción (`status`, `previousStatus`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"subscription.updated"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"subscription.cancelled":{"post":{"operationId":"webhook_subscription_cancelled","summary":"La suscripción se canceló; el acceso sigue hasta `currentPeriodEnd` (después pasa a `expired`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"subscription.cancelled"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"subscription.payment_failed":{"post":{"operationId":"webhook_subscription_payment_failed","summary":"Un cobro falló o no llegó: la suscripción está en `past_due` hasta `graceUntil`","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"subscription.payment_failed"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"payment.succeeded":{"post":{"operationId":"webhook_payment_succeeded","summary":"Se registró un cobro verificado con el proveedor (importe, moneda y periodo; sin datos del pagador)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"payment.succeeded"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.payment_account.failing":{"post":{"operationId":"webhook_partner_payment_account_failing","summary":"La cuenta PayPal del partner falló en la comprobación periódica (solo endpoints del partner)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.payment_account.failing"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.fee.pending":{"post":{"operationId":"webhook_partner_fee_pending","summary":"Se generó la cuota mensual del revendedor (importe, conexiones, vencimiento `dueAt` y corte `cutAt`)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.fee.pending"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.fee.due_soon":{"post":{"operationId":"webhook_partner_fee_due_soon","summary":"La cuota mensual del revendedor vence mañana y sigue sin pagar","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.fee.due_soon"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.fee.overdue":{"post":{"operationId":"webhook_partner_fee_overdue","summary":"La cuota venció sin pagar: el envío y las altas de TODOS sus clientes quedan pausados (402 partner_fee_overdue)","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.fee.overdue"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}},"partner.fee.paid":{"post":{"operationId":"webhook_partner_fee_paid","summary":"Se registró el pago de la cuota: el servicio de sus clientes vuelve solo","parameters":[{"name":"webhook-id","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-timestamp","in":"header","required":true,"schema":{"type":"string"}},{"name":"webhook-signature","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","timestamp","data"],"properties":{"type":{"const":"partner.fee.paid"},"timestamp":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Recibido. Cualquier otra respuesta se reintenta."}}}}},"components":{"securitySchemes":{"apiKey":{"type":"http","scheme":"bearer","bearerFormat":"wq_live_…","description":"API key del panel. Scopes de cliente: `connections:read` (Ver conexiones de WhatsApp y su estado); `connections:write` (Crear, renombrar, vincular (QR), desconectar y borrar conexiones); `conversations:read` (Ver conversaciones); `conversations:write` (Cambiar el estado o la asignación de conversaciones); `messages:read` (Leer mensajes); `messages:send` (Enviar mensajes); `contacts:read` (Ver contactos); `contacts:write` (Crear y editar contactos); `webhooks:read` (Ver endpoints de webhooks y el registro de entregas (sin gestionarlos)); `webhooks:manage` (Gestionar endpoints de webhooks y sus entregas (incluye webhooks:read)); `plans:read` (Ver el catálogo de planes y el plan de la organización); `usage:read` (Ver el uso de la organización); `integrations:manage` (Ver y gestionar integraciones (Google Contacts: estado, ajustes, sincronizar y desconectar)); `groups:manage` (Administrar grupos de WhatsApp: nombre, descripción, foto, miembros, administradores, enlace de invitación y salir); `messages:manage` (Editar y eliminar para todos mensajes enviados por otros miembros (por QR; los propios bastan con messages:send)); `leads:write` (Registrar leads de la web (formularios, productos y páginas) y lanzar su mensaje de bienvenida); `catalog:write` (Cargar y actualizar el catálogo de productos (precios y stock) del asistente IA)."},"partnerToken":{"type":"oauth2","description":"Token de partner de `POST /v1/oauth/token`.","flows":{"clientCredentials":{"tokenUrl":"https://api.waqr.app/v1/oauth/token","scopes":{"partner:read":"Ver el resumen, la capacidad y el libro del partner","partner:customers:read":"Ver clientes","partner:customers:write":"Crear, editar, suspender y reactivar clientes; invitar a su owner","partner:plans:read":"Ver planes del partner","partner:plans:write":"Crear y editar planes del partner","partner:allocations:write":"Asignar y liberar capacidad de clientes","partner:connections:read":"Ver conexiones de los clientes","partner:connections:write":"Crear, vincular (QR), desconectar y borrar conexiones de clientes","partner:usage:read":"Ver el uso agregado y por cliente","partner:webhooks:read":"Ver endpoints de webhooks del partner y sus entregas, sin gestionarlos","partner:webhooks:manage":"Gestionar endpoints de webhooks del partner y sus entregas (incluye partner:webhooks:read)","partner:api-keys:manage":"Emitir, listar y revocar las API keys de integración de los clientes (mensajes y conexiones)","partner:templates:manage":"Ver, crear, borrar y sincronizar las plantillas de WhatsApp oficial de los clientes","partner:credits:write":"Asignar créditos del asistente IA de la billetera del revendedor a sus clientes","partner:fees:read":"Ver las cuotas mensuales del revendedor con WAQR y su detalle","partner:fees:pay":"Pagar las cuotas mensuales del revendedor con PayPal desde su propio panel (iniciar y confirmar el pago)"}}}}},"schemas":{"Problem":{"type":"object","required":["type","title","status","code","requestId"],"properties":{"type":{"type":"string","format":"uri"},"title":{"type":"string"},"status":{"type":"integer"},"code":{"type":"string","enum":["access_session_expired","account_deletion_billing_unavailable","account_deletion_blocked","account_disabled","account_exists","agent_package_unavailable","agent_source_limit","agent_test_quota_exhausted","ai_chain_invalid","ai_key_invalid","ai_model_not_allowed","ai_model_not_ready","ai_unavailable","allocation_in_use","api_key_in_query","api_key_ip_not_allowed","api_key_limit_reached","api_key_not_allowed","api_key_wrong_audience","attachment_not_ready","audio_too_long","bff_credential_invalid","billing_disabled","billing_mode_mismatch","billing_not_available","capture_pending","challenge_expired","chat_budget_exhausted","chat_disabled","chat_seal_invalid","chat_session_required","client_ip_missing","conflict","conflict_resolved","connection_not_connected","connection_offline","connection_paused","connection_quota_exceeded","contact_block_failed","contact_blocked","contact_phone_conflict","contacts_same","conversation_read_only","copilot_quota_exhausted","credential_invalid","credits_managed_by_partner","current_password_invalid","customer_deleted","customer_signup_disabled","email_not_verified","embed_code_invalid","embed_disabled","embed_not_available","embed_session_expired","engine_unsupported","forbidden","google_account_in_use","google_already_linked","google_contacts_disabled","google_disabled","google_email_unverified","google_flow_expired","google_link_expired","google_oauth_failed","google_origin_inactive","google_scope_missing","google_signin_failed","group_action_failed","group_admin_required","group_chats_disabled","group_read_only","handoff_invalid","idempotency_in_progress","idempotency_key_required","idempotency_key_reused","insecure_transport","insufficient_credits","insufficient_scope","integration_exists","integration_not_connected","internal_error","internal_partner_no_allocation","invalid_credentials","invalid_cursor","invalid_grant","invalid_grant_type","invalid_json","invalid_or_expired_code","invalid_parent_origin","invalid_scope","last_owner","media_storage_unavailable","media_type_not_allowed","media_unavailable","member_limit_reached","mentions_unsupported","merge_not_reversible","message_action_failed","message_not_editable","message_not_forwardable","messaging_disabled","not_a_partner","not_found","not_supported_for_engine","notify_channel_unavailable","notify_connection_not_eligible","notify_consent_required","notify_no_house_account","notify_not_a_sender","notify_not_active","notify_recipient_unknown","notify_same_not_allowed","notify_send_failed","notify_template_incompatible","number_already_connected","order_not_approved","organization_limit_reached","organization_required","organization_suspended","origin_not_allowed","partner_capacity_exceeded","partner_fee_not_found","partner_fee_not_payable","partner_fee_overdue","partner_inactive","partner_integration_disabled","partner_org_has_no_connections","password_breached","password_confirmation_required","password_not_set","password_required","payload_too_large","payment_account_not_verified","payment_account_required","payment_pending","payment_provider_error","payment_required","pin_limit_reached","plan_feature_required","plan_upgrade_required","quantity_below_usage","rate_limited","reauthentication_required","receipt_not_available","scope_exceeds_role","search_term_too_short","send_busy","service_unavailable","session_host_mismatch","session_revoked","slug_reserved","slug_taken","sso_user_not_allowed","staff_session_expired","subdomain_change_limit","subscription_exists","subscription_not_active","surface_not_embedded","token_invalid","too_many_streams","totp_enrollment_code_required","totp_invalid","turnstile_failed","turnstile_required","turnstile_unavailable","unauthenticated","unsupported_media_type","upload_quota_exceeded","validation_failed","waba_disabled","waba_meta_unavailable","waba_not_configured","waba_phone_in_use","waba_signup_failed","waba_signup_invalid","waba_template_exists","waba_template_header_required","waba_template_invalid","waba_template_not_found","waba_token_invalid","waba_window_closed","webhook_endpoint_disabled","webhook_endpoint_limit_reached","webhook_unauthorized","wrong_environment"]},"detail":{"type":"string"},"errors":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"message":{"type":"string"}}}},"requestId":{"type":"string"}},"additionalProperties":true},"ApiKey":{"type":"object","properties":{"id":{"type":"string","pattern":"^key_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`key_…`)."},"name":{"type":"string"},"prefix":{"type":"string"},"audience":{"type":"string"},"environment":{"type":"string"},"scopes":{"type":"array","items":{"type":"string"}},"connectionIds":{"anyOf":[{"type":"array","items":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."}},{"type":"null"}],"description":"Conexiones a las que se limita; null = todas."},"origin":{"type":["string","null"]},"allowedCidrs":{"type":"array","items":{"type":"string"},"description":"IPs o rangos permitidos; vacío = cualquiera."},"status":{"type":"string","enum":["active","revoked","expired"]},"createdBy":{"anyOf":[{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},{"type":"null"}]},"lastUsedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastUsedIp":{"type":["string","null"]},"expiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"revokedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","name","prefix","audience","environment","scopes","connectionIds","origin","allowedCidrs","status","createdBy","lastUsedAt","lastUsedIp","expiresAt","revokedAt","createdAt"],"description":"Clave de API (nunca el secreto, salvo al emitirla)."},"Attachment":{"type":"object","properties":{"id":{"type":"string","pattern":"^att_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`att_…`)."},"kind":{"type":"string","description":"`image`, `audio`, `video`, `document` o `sticker`."},"mimeType":{"type":["string","null"]},"fileName":{"type":["string","null"]},"sizeBytes":{"anyOf":[{"type":"integer"},{"type":"null"}]},"width":{"anyOf":[{"type":"integer"},{"type":"null"}]},"height":{"anyOf":[{"type":"integer"},{"type":"null"}]},"durationMs":{"anyOf":[{"type":"integer"},{"type":"null"}]},"status":{"type":"string","enum":["pending","stored","failed","expired"],"description":"`stored`: descargable con `GET /v1/messages/{id}/attachments/{aid}`."},"failureReason":{"type":"string"},"sha256":{"description":"Solo con `status: stored`.","type":["string","null"]}},"required":["id","kind","mimeType","fileName","sizeBytes","width","height","durationMs","status"],"description":"Adjunto de un mensaje."},"CapacityAllocation":{"type":"object","properties":{"id":{"type":"string","pattern":"^alc_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`alc_…`)."},"resource":{"type":"string","enum":["whatsapp_connection"]},"quantity":{"type":"integer"},"planId":{"anyOf":[{"type":"string","pattern":"^pplan_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`pplan_…`)."},{"type":"null"}]},"status":{"type":"string","enum":["trialing","active","released","expired"]},"validFrom":{"type":"string","format":"date-time"},"validUntil":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"description":"Fin de la prueba; null si no vence."},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","resource","quantity","planId","status","validFrom","validUntil","createdAt","updatedAt"],"description":"Capacidad asignada a un cliente."},"CapacityLedgerEntry":{"type":"object","properties":{"id":{"type":"string","pattern":"^led_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`led_…`)."},"kind":{"type":"string","enum":["pool_set","pool_adjust","allocate","release","resize","expire"]},"resource":{"type":"string","enum":["whatsapp_connection"]},"delta":{"type":"integer"},"totalAfter":{"type":"integer"},"allocatedAfter":{"type":"integer"},"customerId":{"anyOf":[{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},{"type":"null"}]},"allocationId":{"anyOf":[{"type":"string","pattern":"^alc_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`alc_…`)."},{"type":"null"}]},"reason":{"type":["string","null"]},"actor":{"type":"object","properties":{"type":{"type":"string","enum":["user","partner_user","admin","system"]},"id":{"anyOf":[{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},{"type":"null"}],"description":"Solo si fue un usuario."}},"required":["type","id"]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","kind","resource","delta","totalAfter","allocatedAfter","customerId","allocationId","reason","actor","createdAt"],"description":"Movimiento del libro de capacidad."},"CapacityPool":{"type":"object","properties":{"id":{"anyOf":[{"type":"string","pattern":"^pool_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`pool_…`)."},{"type":"null"}],"description":"Null si nunca se concedió capacidad."},"resource":{"type":"string","enum":["whatsapp_connection"]},"total":{"type":"integer"},"allocated":{"type":"integer"},"available":{"type":"integer","description":"Lo que aún se puede asignar (0 si el partner no está activo)."},"effectiveTotal":{"type":"integer"},"status":{"type":"string","enum":["active","over_allocated","inactive"]},"maxPerCustomer":{"anyOf":[{"type":"integer"},{"type":"null"}]},"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","resource","total","allocated","available","effectiveTotal","status","maxPerCustomer","updatedAt"],"description":"Bolsa de capacidad del partner."},"Connection":{"type":"object","properties":{"id":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"label":{"type":"string"},"status":{"type":"string","enum":["pending_qr","connecting","connected","disconnected","logged_out","banned","paused"],"description":"Estado; `paused` si la conexión está pausada (ver `pausedReason`)."},"engine":{"type":"string","enum":["evolution","waba"],"description":"`evolution`: por QR; `waba`: WhatsApp oficial (Meta)."},"phoneE164":{"type":["string","null"]},"connectedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastSeenAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"disconnectedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"groupChatsEnabled":{"type":"boolean"},"groupChatsActive":{"type":"boolean","description":"Si los chats de grupo están activos de verdad en esta conexión."},"capabilities":{"type":"object","properties":{"react":{"type":"boolean"},"edit":{"type":"boolean"},"deleteForEveryone":{"type":"boolean"},"forward":{"type":"boolean"},"messageInfo":{"type":"boolean"}},"required":["react","edit","deleteForEveryone","forward","messageInfo"],"description":"Acciones sobre mensajes que admite el motor de la conexión."},"continuity":{"anyOf":[{"type":"object","properties":{"fromConnectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"fromEngine":{"type":"string","enum":["evolution","waba"]},"fromLabel":{"type":"string"},"fromDeletedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"movedConversations":{"type":"integer"},"mergedConversations":{"type":"integer"},"movedMessages":{"type":"integer"},"movedGroups":{"type":"integer"},"at":{"type":"string","format":"date-time"}},"required":["fromConnectionId","fromEngine","fromLabel","fromDeletedAt","movedConversations","mergedConversations","movedMessages","movedGroups","at"]},{"type":"null"}],"description":"Chats heredados de otra conexión con el mismo número; null si no hubo."},"numberChangedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"supersededBy":{"anyOf":[{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Conexión que heredó los chats de esta."},{"type":"null"}]},"conflict":{"anyOf":[{"type":"object","properties":{"reason":{"type":"string","const":"number_already_connected"},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"label":{"type":["string","null"]}},"required":["reason","connectionId","label"]},{"type":"null"}],"description":"El número ya está activo en otra conexión."},"previousNumbers":{"description":"Números anteriores (solo en el detalle).","type":"array","items":{"type":"object","properties":{"phoneE164":{"type":"string"},"from":{"type":"string","format":"date-time"},"to":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["phoneE164","from","to"]}},"lastError":{"description":"Último error del motor; solo para quien gestiona conexiones.","type":["string","null"]},"pausedReason":{"anyOf":[{"type":"string","enum":["trial_expired","trial_number_used","billing","manual","partner_suspended","plan_limit"]},{"type":"null"}]},"pausedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"},"waba":{"description":"Solo en conexiones `waba`.","anyOf":[{"$ref":"#/components/schemas/WabaAccount"},{"type":"null"}]},"historyImport":{"description":"Última importación de historial (solo en el detalle de una conexión por QR).","anyOf":[{"$ref":"#/components/schemas/HistoryImport"},{"type":"null"}]},"historyImports":{"description":"Última importación de cada alcance (conexiones por QR).","type":"array","items":{"$ref":"#/components/schemas/HistoryImport"}}},"required":["id","label","status","engine","phoneE164","connectedAt","lastSeenAt","disconnectedAt","groupChatsEnabled","groupChatsActive","capabilities","continuity","numberChangedAt","supersededBy","conflict","pausedReason","pausedAt","createdAt","updatedAt"],"description":"Conexión de WhatsApp (por QR o WhatsApp oficial).","examples":[{"id":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","label":"Ventas","status":"connected","engine":"evolution","phoneE164":"+51987654321","connectedAt":"2026-11-20T15:04:05.000Z","lastSeenAt":"2026-12-01T09:30:00.000Z","disconnectedAt":null,"groupChatsEnabled":false,"groupChatsActive":false,"capabilities":{"react":true,"edit":true,"deleteForEveryone":true,"forward":true,"messageInfo":true},"continuity":null,"numberChangedAt":null,"supersededBy":null,"conflict":null,"lastError":null,"pausedReason":null,"pausedAt":null,"createdAt":"2026-11-20T15:00:00.000Z","updatedAt":"2026-12-01T09:30:00.000Z","historyImports":[]}]},"ConnectionQr":{"type":"object","properties":{"qr":{"description":"QR como imagen (data URL) o texto; null si ya está conectada.","type":["string","null"]},"expiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"status":{"type":"string","enum":["pending_qr","connecting","connected","disconnected","logged_out","banned","deleted"]},"pairingCode":{"type":"string"}},"required":["qr","expiresAt","status"],"description":"Código QR para vincular el número (caduca en ~60 s)."},"ConnectionQuota":{"type":"object","properties":{"quota":{"type":"integer"},"used":{"type":"integer"},"available":{"type":"integer"},"unlimited":{"type":"boolean","const":true}},"required":["quota","used","available"],"description":"Cupo de conexiones de la organización."},"Contact":{"type":"object","properties":{"id":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"displayName":{"type":"string","description":"Nombre a mostrar (nunca inventado: si no hay nombre, el número o un genérico)."},"displayNameSource":{"type":"string","description":"`name`, `user`, `google`, `api`, `wa_profile`, `wa_contacts_event` o, sin nombre, `phone`/`none`."},"phoneE164":{"description":"Número de WhatsApp (E.164) más reciente.","type":["string","null"]},"userId":{"description":"Id de usuario de WhatsApp oficial (BSUID); sirve de destino en `toUserId`.","type":["string","null"]},"username":{"description":"Último nombre de usuario de WhatsApp visto, sin `@`. No identifica.","type":["string","null"]},"givenName":{"type":["string","null"]},"familyName":{"type":["string","null"]},"company":{"type":["string","null"]},"notes":{"type":["string","null"]},"createdVia":{"type":"string","description":"Origen: `inbound_message`, `outbound_message`, `group_message`, `manual`, `google`, `api`…"},"lastInteractionAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"userEditedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"},"avatar":{"anyOf":[{"type":"object","properties":{"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["updatedAt"]},{"type":"null"}],"description":"Foto de perfil guardada (el binario se descarga en la ruta `/avatar`); null si no hay."}},"required":["id","displayName","displayNameSource","phoneE164","userId","username","givenName","familyName","company","notes","createdVia","lastInteractionAt","userEditedAt","createdAt","updatedAt","avatar"],"description":"Contacto: una persona única por organización (puede tener varios números e identidades).","examples":[{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"givenName":null,"familyName":null,"company":null,"notes":null,"createdVia":"inbound_message","lastInteractionAt":"2026-12-01T10:15:00.000Z","userEditedAt":null,"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z","avatar":null}]},"ContactDetail":{"type":"object","properties":{"id":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"displayName":{"type":"string","description":"Nombre a mostrar (nunca inventado: si no hay nombre, el número o un genérico)."},"displayNameSource":{"type":"string","description":"`name`, `user`, `google`, `api`, `wa_profile`, `wa_contacts_event` o, sin nombre, `phone`/`none`."},"phoneE164":{"description":"Número de WhatsApp (E.164) más reciente.","type":["string","null"]},"userId":{"description":"Id de usuario de WhatsApp oficial (BSUID); sirve de destino en `toUserId`.","type":["string","null"]},"username":{"description":"Último nombre de usuario de WhatsApp visto, sin `@`. No identifica.","type":["string","null"]},"givenName":{"type":["string","null"]},"familyName":{"type":["string","null"]},"company":{"type":["string","null"]},"notes":{"type":["string","null"]},"createdVia":{"type":"string","description":"Origen: `inbound_message`, `outbound_message`, `group_message`, `manual`, `google`, `api`…"},"lastInteractionAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"userEditedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"},"avatar":{"anyOf":[{"type":"object","properties":{"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["updatedAt"]},{"type":"null"}],"description":"Foto de perfil guardada (el binario se descarga en la ruta `/avatar`); null si no hay."},"mergedFrom":{"description":"Si pediste un contacto ya fusionado, su id (se devuelve el superviviente).","type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$"},"merges":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^cmg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`cmg_…`)."},"mergedContactId":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"reason":{"type":"string"},"reversible":{"type":"boolean"},"createdAt":{"type":"string","format":"date-time"}},"required":["id","mergedContactId","reason","reversible","createdAt"]}},"externalLinks":{"type":"array","items":{"type":"object","properties":{"provider":{"type":"string","const":"google"},"resourceName":{"type":"string"},"state":{"type":"string"},"lastSyncedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["provider","resourceName","state","lastSyncedAt"]}},"phones":{"type":"array","items":{"type":"object","properties":{"value":{"type":"string"},"label":{"type":["string","null"]},"source":{"type":"string"},"isWhatsapp":{"type":["boolean","null"]}},"required":["value","label","source","isWhatsapp"]},"description":"Teléfonos de agenda (declarados, de Google o de leads)."},"emails":{"type":"array","items":{"type":"object","properties":{"value":{"type":"string"},"label":{"type":["string","null"]},"source":{"type":"string"}},"required":["value","label","source"]}},"identities":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^cid_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`cid_…`)."},"kind":{"type":"string","description":"`wa_pn` (número), `wa_lid`, `wa_bsuid`…"},"value":{"type":"string"},"jid":{"type":["string","null"]},"firstSeenAt":{"type":"string","format":"date-time"},"lastSeenAt":{"type":"string","format":"date-time"}},"required":["id","kind","value","jid","firstSeenAt","lastSeenAt"]},"description":"Identidades de WhatsApp del contacto."},"nameObservations":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"value":{"type":"string"},"confidence":{"type":"string"},"timesSeen":{"type":"integer"},"connectionId":{"anyOf":[{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},{"type":"null"}]},"firstSeenAt":{"type":"string","format":"date-time"},"observedAt":{"type":"string","format":"date-time"}},"required":["source","value","confidence","timesSeen","connectionId","firstSeenAt","observedAt"]}},"conversations":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"status":{"type":"string"},"unreadCount":{"type":"integer"},"lastMessageAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","connectionId","status","unreadCount","lastMessageAt"]}},"groups":{"type":"array","items":{"type":"object","properties":{"groupId":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"participantId":{"type":"string","pattern":"^gpt_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`gpt_…`)."},"displayName":{"type":"string"},"role":{"type":"string"},"leftAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["groupId","participantId","displayName","role","leftAt"]}}},"required":["id","displayName","displayNameSource","phoneE164","userId","username","givenName","familyName","company","notes","createdVia","lastInteractionAt","userEditedAt","createdAt","updatedAt","avatar","merges","externalLinks","phones","emails","identities","nameObservations","conversations","groups"],"description":"Ficha completa de un contacto."},"ContactSummary":{"type":"object","properties":{"id":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"displayName":{"type":"string"},"displayNameSource":{"type":"string","description":"`name`, `user`, `google`, `api`, `wa_profile`, `wa_contacts_event` o, sin nombre, `phone`/`none`."},"phoneE164":{"type":["string","null"]},"userId":{"description":"Id de usuario de WhatsApp oficial (BSUID), si se conoce.","type":["string","null"]},"username":{"description":"Último nombre de usuario de WhatsApp visto (no identifica).","type":["string","null"]},"avatar":{"anyOf":[{"type":"object","properties":{"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["updatedAt"]},{"type":"null"}],"description":"Foto de perfil guardada (el binario se descarga en la ruta `/avatar`); null si no hay."},"blockedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","displayName","displayNameSource","phoneE164","userId","username","avatar","blockedAt"],"description":"Resumen de un contacto (en conversaciones y participantes)."},"Conversation":{"type":"object","properties":{"id":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"kind":{"type":"string","enum":["direct","group"]},"status":{"type":"string","enum":["open","closed","archived"]},"unreadCount":{"type":"integer"},"lastMessageAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastMessage":{"anyOf":[{"type":"object","properties":{"id":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"preview":{"type":["string","null"]},"direction":{"anyOf":[{"type":"string","enum":["inbound","outbound"]},{"type":"null"}]}},"required":["id","preview","direction"]},{"type":"null"}]},"lastReadAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastInboundAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"replyWindowExpiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"description":"Fin de la ventana de 24 h para responder sin plantilla (WhatsApp oficial)."},"assignedUserId":{"anyOf":[{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},{"type":"null"}]},"pinnedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"labels":{"type":"array","items":{"$ref":"#/components/schemas/ConversationLabel"}},"mutedUntil":{"anyOf":[{"anyOf":[{"type":"string","format":"date-time"},{"type":"string","const":"forever"}]},{"type":"null"}],"description":"Silenciada hasta esa fecha, `forever` o null."},"muted":{"type":"boolean"},"pinnedMessages":{"type":"array","items":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"preview":{"type":"string"},"type":{"type":"string"},"direction":{"type":"string","enum":["inbound","outbound"]},"pinnedBy":{"anyOf":[{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},{"type":"null"}]},"pinnedAt":{"type":"string","format":"date-time"},"expiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["messageId","preview","type","direction","pinnedBy","pinnedAt","expiresAt"]},"description":"Mensajes fijados vigentes (máximo 3)."},"contact":{"description":"Solo en conversaciones `direct`.","anyOf":[{"$ref":"#/components/schemas/ContactSummary"},{"type":"null"}]},"group":{"description":"Solo en conversaciones `group`.","anyOf":[{"$ref":"#/components/schemas/GroupSummary"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","connectionId","kind","status","unreadCount","lastMessageAt","lastMessage","lastReadAt","lastInboundAt","replyWindowExpiresAt","assignedUserId","pinnedAt","labels","mutedUntil","muted","pinnedMessages","createdAt","updatedAt"],"description":"Conversación (chat 1:1 o de grupo) de una conexión.","examples":[{"id":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","kind":"direct","status":"open","unreadCount":2,"lastMessageAt":"2026-12-01T10:15:00.000Z","lastMessage":{"id":"msg_01JF8ZB5E6F7G8H9J0K1M2N3P4","preview":"¿Tienen envío a Lima?","direction":"inbound"},"lastReadAt":"2026-12-01T09:00:00.000Z","lastInboundAt":"2026-12-01T10:15:00.000Z","replyWindowExpiresAt":"2026-12-02T10:15:00.000Z","assignedUserId":null,"pinnedAt":null,"labels":[],"mutedUntil":null,"muted":false,"pinnedMessages":[],"contact":{"id":"ct_01JF8Z7B3C4D5E6F7G8H9J0K1M","displayName":"María Pérez","displayNameSource":"wa_profile","phoneE164":"+51912345678","userId":null,"username":null,"avatar":null,"blockedAt":null},"createdAt":"2026-11-25T18:00:00.000Z","updatedAt":"2026-12-01T10:15:00.000Z"}]},"ConversationAgent":{"type":"object","properties":{"enabled":{"type":"boolean","description":"El agente de IA responde en esta conversación."},"paused":{"type":"boolean"},"pausedReason":{"type":["string","null"]}},"required":["enabled","paused","pausedReason"],"description":"Estado del agente de IA en la conversación."},"ConversationDetail":{"type":"object","properties":{"id":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"kind":{"type":"string","enum":["direct","group"]},"status":{"type":"string","enum":["open","closed","archived"]},"unreadCount":{"type":"integer"},"lastMessageAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastMessage":{"anyOf":[{"type":"object","properties":{"id":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"preview":{"type":["string","null"]},"direction":{"anyOf":[{"type":"string","enum":["inbound","outbound"]},{"type":"null"}]}},"required":["id","preview","direction"]},{"type":"null"}]},"lastReadAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastInboundAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"replyWindowExpiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"description":"Fin de la ventana de 24 h para responder sin plantilla (WhatsApp oficial)."},"assignedUserId":{"anyOf":[{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},{"type":"null"}]},"pinnedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"labels":{"type":"array","items":{"$ref":"#/components/schemas/ConversationLabel"}},"mutedUntil":{"anyOf":[{"anyOf":[{"type":"string","format":"date-time"},{"type":"string","const":"forever"}]},{"type":"null"}],"description":"Silenciada hasta esa fecha, `forever` o null."},"muted":{"type":"boolean"},"pinnedMessages":{"type":"array","items":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"preview":{"type":"string"},"type":{"type":"string"},"direction":{"type":"string","enum":["inbound","outbound"]},"pinnedBy":{"anyOf":[{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`usr_…`)."},{"type":"null"}]},"pinnedAt":{"type":"string","format":"date-time"},"expiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["messageId","preview","type","direction","pinnedBy","pinnedAt","expiresAt"]},"description":"Mensajes fijados vigentes (máximo 3)."},"contact":{"description":"Solo en conversaciones `direct`.","anyOf":[{"$ref":"#/components/schemas/ContactSummary"},{"type":"null"}]},"group":{"description":"Solo en conversaciones `group`.","anyOf":[{"$ref":"#/components/schemas/GroupSummary"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"},"lead":{"anyOf":[{"$ref":"#/components/schemas/LeadContext"},{"type":"null"}]},"agent":{"$ref":"#/components/schemas/ConversationAgent"}},"required":["id","connectionId","kind","status","unreadCount","lastMessageAt","lastMessage","lastReadAt","lastInboundAt","replyWindowExpiresAt","assignedUserId","pinnedAt","labels","mutedUntil","muted","pinnedMessages","createdAt","updatedAt","lead","agent"],"description":"Conversación con el lead web y el estado del agente de IA."},"ConversationLabel":{"type":"object","properties":{"id":{"type":"string","pattern":"^lbl_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`lbl_…`)."},"name":{"type":"string"},"color":{"type":"string"}},"required":["id","name","color"],"description":"Etiqueta de conversación."},"CreditLedgerEntry":{"type":"object","properties":{"id":{"type":"string","pattern":"^crl_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`crl_…`)."},"kind":{"type":"string","description":"`purchase`, `reply`, `grant`, `adjustment`, `refund`, `expire`, `partner_assign`, `partner_purchase`…"},"credits":{"type":"integer","description":"Con signo."},"balance":{"type":"integer","description":"Saldo después del movimiento."},"note":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","kind","credits","balance","note","createdAt"],"description":"Movimiento de créditos de IA (los últimos 50)."},"CreditLot":{"type":"object","properties":{"id":{"type":"string","pattern":"^clt_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`clt_…`)."},"source":{"type":"string","description":"Origen: `purchase`, `partner`, `adjustment`…"},"credits":{"type":"integer"},"remaining":{"type":"integer"},"expiresAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","source","credits","remaining","expiresAt","createdAt"],"description":"Lote de créditos de IA (los últimos 50)."},"GoogleContactsIntegration":{"type":"object","properties":{"id":{"type":"string","pattern":"^int_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`int_…`)."},"provider":{"type":"string","const":"google_contacts"},"status":{"type":"string","enum":["active","needs_reconnect","disconnected"]},"accountEmail":{"type":["string","null"]},"authorizedBy":{"type":"string","pattern":"^usr_[0-9A-HJKMNP-TV-Z]{26}$","description":"Usuario que conectó la cuenta de Google."},"settings":{"type":"object","properties":{"syncScope":{"type":"string","enum":["saved","all_with_number"],"description":"`saved`: solo los contactos guardados; `all_with_number`: todos los que tienen número."},"importContacts":{"type":"boolean"}},"required":["syncScope","importContacts"]},"lastSyncAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastSyncStatus":{"type":["string","null"]},"lastError":{"type":["string","null"]},"lastFullSyncAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"nextSyncAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"syncing":{"type":"boolean"},"stats":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":["number","string"]},"description":"Contadores de la última sincronización (`mode`, `fetched`, `imported`, `matched`, `pushed`, `created`, `conflicts`…); vacío hasta la primera."},"linkedContacts":{"type":"integer"},"openConflicts":{"type":"integer"},"deletedInGoogle":{"type":"integer"},"connectedAt":{"type":"string","format":"date-time"},"needsReconnectAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","provider","status","accountEmail","authorizedBy","settings","lastSyncAt","lastSyncStatus","lastError","lastFullSyncAt","nextSyncAt","syncing","stats","linkedContacts","openConflicts","deletedInGoogle","connectedAt","needsReconnectAt"],"description":"Integración de Google Contacts de la organización (nunca sus tokens)."},"Group":{"type":"object","properties":{"id":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"jid":{"type":"string"},"subject":{"type":["string","null"]},"displayName":{"type":"string"},"description":{"type":["string","null"]},"ownerJid":{"type":["string","null"]},"createdAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"description":"Cuándo se creó el grupo en WhatsApp, si se sabe."},"sizeObserved":{"anyOf":[{"type":"integer"},{"type":"null"}]},"participantCount":{"type":"integer"},"announce":{"description":"Solo los admins envían mensajes.","type":["boolean","null"]},"restrict":{"description":"Solo los admins cambian los datos del grupo.","type":["boolean","null"]},"linkedParentJid":{"type":["string","null"]},"status":{"type":"string","description":"`observed`, `active`, `left` o `ignored`."},"readOnly":{"type":"boolean"},"conversationId":{"anyOf":[{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},{"type":"null"}]},"firstSeenAt":{"type":"string","format":"date-time"},"metadataFetchedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"leftAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"avatar":{"anyOf":[{"type":"object","properties":{"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["updatedAt"]},{"type":"null"}],"description":"Foto de perfil guardada (el binario se descarga en la ruta `/avatar`); null si no hay."}},"required":["id","connectionId","jid","subject","displayName","description","ownerJid","createdAt","sizeObserved","participantCount","announce","restrict","linkedParentJid","status","readOnly","conversationId","firstSeenAt","metadataFetchedAt","leftAt","avatar"],"description":"Grupo de WhatsApp de una conexión."},"GroupDetail":{"type":"object","properties":{"id":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"jid":{"type":"string"},"subject":{"type":["string","null"]},"displayName":{"type":"string"},"description":{"type":["string","null"]},"ownerJid":{"type":["string","null"]},"createdAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"description":"Cuándo se creó el grupo en WhatsApp, si se sabe."},"sizeObserved":{"anyOf":[{"type":"integer"},{"type":"null"}]},"participantCount":{"type":"integer"},"announce":{"description":"Solo los admins envían mensajes.","type":["boolean","null"]},"restrict":{"description":"Solo los admins cambian los datos del grupo.","type":["boolean","null"]},"linkedParentJid":{"type":["string","null"]},"status":{"type":"string","description":"`observed`, `active`, `left` o `ignored`."},"readOnly":{"type":"boolean"},"conversationId":{"anyOf":[{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},{"type":"null"}]},"firstSeenAt":{"type":"string","format":"date-time"},"metadataFetchedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"leftAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"avatar":{"anyOf":[{"type":"object","properties":{"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["updatedAt"]},{"type":"null"}],"description":"Foto de perfil guardada (el binario se descarga en la ruta `/avatar`); null si no hay."},"participants":{"type":"array","items":{"$ref":"#/components/schemas/GroupParticipant"},"description":"Primeros 200 participantes activos."},"participantsNextCursor":{"type":["string","null"]},"manage":{"$ref":"#/components/schemas/GroupManage"}},"required":["id","connectionId","jid","subject","displayName","description","ownerJid","createdAt","sizeObserved","participantCount","announce","restrict","linkedParentJid","status","readOnly","conversationId","firstSeenAt","metadataFetchedAt","leftAt","avatar","participants","participantsNextCursor","manage"],"description":"Grupo con sus participantes."},"GroupManage":{"type":"object","properties":{"canManage":{"type":"boolean"},"connectionRole":{"anyOf":[{"type":"string","enum":["member","admin","superadmin"]},{"type":"null"}]},"connectionParticipantId":{"anyOf":[{"type":"string","pattern":"^gpt_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`gpt_…`)."},{"type":"null"}]},"infoAdminsOnly":{"type":"boolean"}},"required":["canManage","connectionRole","connectionParticipantId","infoAdminsOnly"],"description":"Qué acciones de administración puede hacer la conexión en el grupo."},"GroupParticipant":{"type":"object","properties":{"id":{"type":"string","pattern":"^gpt_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`gpt_…`)."},"jid":{"type":"string"},"altJid":{"type":["string","null"]},"role":{"type":"string","enum":["member","admin","superadmin"]},"displayName":{"type":["string","null"]},"contact":{"anyOf":[{"$ref":"#/components/schemas/ContactSummary"},{"type":"null"}]},"joinedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"leftAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastSeenAt":{"type":"string","format":"date-time"},"lastMessageAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","jid","altJid","role","displayName","contact","joinedAt","leftAt","lastSeenAt","lastMessageAt"],"description":"Participante de un grupo."},"GroupSummary":{"type":"object","properties":{"id":{"type":"string","pattern":"^grp_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`grp_…`)."},"subject":{"type":["string","null"]},"displayName":{"type":"string"},"status":{"type":"string"},"participantCount":{"type":"integer"},"readOnly":{"type":"boolean","description":"La conexión ya no está en el grupo."},"avatar":{"anyOf":[{"type":"object","properties":{"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["updatedAt"]},{"type":"null"}],"description":"Foto de perfil guardada (el binario se descarga en la ruta `/avatar`); null si no hay."}},"required":["id","subject","displayName","status","participantCount","readOnly","avatar"],"description":"Resumen de un grupo (en conversaciones de grupo)."},"HistoryImport":{"type":"object","properties":{"status":{"type":"string","enum":["scheduled","running","paused","done","failed","skipped"]},"scope":{"type":"string","enum":["all","groups"]},"includedGroups":{"type":"boolean"},"since":{"type":"string","format":"date-time"},"until":{"type":"string","format":"date-time"},"total":{"anyOf":[{"type":"integer"},{"type":"null"}]},"scanned":{"type":"integer"},"imported":{"type":"integer"},"duplicates":{"type":"integer"},"progress":{"description":"Avance de 0 a 1; null hasta leer la primera página.","type":["number","null"]},"notBefore":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"startedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"finishedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastError":{"description":"Solo para quien gestiona conexiones.","type":["string","null"]}},"required":["status","scope","includedGroups","since","until","total","scanned","imported","duplicates","progress","notBefore","startedAt","finishedAt","updatedAt"],"description":"Importación del historial de chats de una conexión por QR."},"Invitation":{"type":"object","properties":{"id":{"type":"string","pattern":"^inv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`inv_…`)."},"email":{"type":"string"},"role":{"type":"string","enum":["owner","admin","agent","developer","viewer"]},"status":{"type":"string","enum":["pending","accepted","revoked","expired"]},"expiresAt":{"type":"string","format":"date-time"},"createdAt":{"type":"string","format":"date-time"}},"required":["id","email","role","status","expiresAt","createdAt"],"description":"Invitación a una organización (nunca el token)."},"Lead":{"type":"object","properties":{"id":{"type":"string","pattern":"^lead_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`lead_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"conversationId":{"anyOf":[{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},{"type":"null"}]},"contact":{"type":"object","properties":{"id":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},"name":{"type":["string","null"]},"phone":{"type":"string"},"email":{"type":["string","null"]}},"required":["id","name","phone","email"]},"source":{"type":"string"},"site":{"type":["string","null"]},"variant":{"type":"string"},"page":{},"product":{},"form":{},"topic":{},"welcome":{"type":"object","properties":{"status":{"type":"string"},"reason":{"type":["string","null"]},"at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["status","reason","at"]},"repliedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"followUp":{"type":"object","properties":{"status":{"type":["string","null"]},"reason":{"type":["string","null"]},"at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["status","reason","at"]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","connectionId","conversationId","contact","source","site","variant","page","product","form","topic","welcome","repliedAt","followUp","createdAt"],"description":"Lead que llegó de una web."},"LeadContext":{"type":"object","properties":{"id":{"type":"string","pattern":"^lead_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`lead_…`)."},"variant":{"type":"string"},"page":{},"product":{},"form":{},"topic":{},"createdAt":{"type":"string","format":"date-time"}},"required":["id","variant","page","product","form","topic","createdAt"],"description":"Último lead web del contacto de la conversación."},"Message":{"type":"object","properties":{"id":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"conversationType":{"type":"string","enum":["direct","group"]},"direction":{"type":"string","enum":["inbound","outbound"]},"externalId":{"description":"Id de WhatsApp del mensaje; null mientras un saliente está `pending` y en las notas internas.","type":["string","null"]},"type":{"type":"string","description":"`text`, `image`, `audio`, `video`, `document`, `sticker`, `location`, `contact`, `reaction`, `poll`, `template`, `note`, `system`, `unknown`…"},"body":{"description":"Texto o pie del mensaje; null si se eliminó.","type":["string","null"]},"status":{"type":"string","description":"Saliente: `pending`, `sent`, `delivered`, `read` o `failed`. Entrante: estado de recepción."},"failureReason":{"description":"Solo en salientes `failed`.","type":["string","null"]},"failureDetail":{"description":"Solo en salientes `failed`.","type":["string","null"]},"pricing":{"description":"Precio que asignó Meta (WhatsApp oficial), si llegó.","type":"object","properties":{"billable":{"type":["boolean","null"]},"category":{"type":["string","null"]},"pricingModel":{"type":["string","null"]},"type":{"type":["string","null"]}},"required":["billable","category","pricingModel","type"]},"clientKey":{"description":"La `Idempotency-Key` con la que se pidió el envío (salientes).","type":"string"},"sender":{"$ref":"#/components/schemas/MessageSender"},"sentBy":{"anyOf":[{"type":"object","properties":{"kind":{"type":"string","enum":["user","api"]},"id":{"type":"string"},"name":{"type":"string"}},"required":["kind","id","name"]},{"type":"null"}],"description":"Quién lo envió desde WAQR (persona del panel o API key); null si se envió desde el teléfono."},"author":{"description":"Respuesta del agente de IA.","type":"string","const":"ai"},"starred":{"type":"boolean"},"hidden":{"type":"boolean","description":"Oculto en WAQR («eliminar para mí»)."},"quoted":{"anyOf":[{"type":"object","properties":{"messageId":{"anyOf":[{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},{"type":"null"}]},"externalId":{"type":["string","null"]}},"required":["messageId","externalId"]},{"type":"null"}],"description":"Mensaje citado; `messageId` es null si no está en WAQR."},"reaction":{"description":"Solo en mensajes `reaction`: a qué mensaje y con qué emoji (null = quitada).","type":"object","properties":{"messageId":{"anyOf":[{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},{"type":"null"}]},"externalId":{"type":["string","null"]},"emoji":{"type":["string","null"]}},"required":["messageId","externalId","emoji"]},"metadata":{"type":"object","properties":{"forwarded":{"type":"boolean","const":true},"forwardedFrom":{"type":["string","null"]}},"required":["forwarded","forwardedFrom"]},"location":{"type":"object","properties":{"latitude":{"type":"number"},"longitude":{"type":"number"},"name":{"type":"string"},"address":{"type":"string"}},"required":["latitude","longitude"]},"contactCard":{"type":"object","properties":{"displayName":{"type":"string"},"vcard":{"type":"string"}}},"attachments":{"type":"array","items":{"$ref":"#/components/schemas/Attachment"}},"sentAt":{"type":"string","format":"date-time"},"editedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"deletedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","conversationId","connectionId","conversationType","direction","externalId","type","body","status","sender","starred","hidden","quoted","attachments","sentAt","editedAt","deletedAt"],"description":"Mensaje (entrante, saliente o nota interna).","examples":[{"id":"msg_01JF8ZC6F7G8H9J0K1M2N3P4Q5","conversationId":"conv_01JF8Z9C4D5E6F7G8H9J0K1M2N","connectionId":"conn_01JF8Z5Q2W3E4R5T6Y7V8M9N0P","conversationType":"direct","direction":"outbound","externalId":null,"type":"text","body":"Hola María, sí: enviamos a todo Lima.","status":"pending","clientKey":"5f0c2b9e-8d1a-4c6b-9f3e-2a7d4e1b0c9a","sender":{"kind":"connection","jid":null,"origin":"waqr"},"sentBy":{"kind":"api","id":"key_01JF8ZD7G8H9J0K1M2N3P4Q5R6","name":"CRM"},"starred":false,"hidden":false,"quoted":null,"attachments":[],"sentAt":"2026-12-01T10:16:00.000Z","editedAt":null,"deletedAt":null}]},"MessageInfo":{"type":"object","properties":{"message":{"type":"object","properties":{"id":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"direction":{"type":"string","enum":["inbound","outbound"]}},"required":["id","conversationId","direction"]},"status":{"type":"string"},"sentAt":{"type":"string","format":"date-time"},"deliveredAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"readAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"playedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"sentBy":{"anyOf":[{"type":"object","properties":{"kind":{"type":"string","enum":["user","api"]},"id":{"type":"string"},"name":{"type":"string"}},"required":["kind","id","name"]},{"type":"null"}],"description":"Quién lo envió desde WAQR (persona del panel o API key); null si se envió desde el teléfono."},"origin":{"anyOf":[{"type":"string","enum":["waqr","device"]},{"type":"null"}]},"failureReason":{"type":["string","null"]},"forwarded":{"type":"boolean"},"forwardedFrom":{"type":["string","null"]},"edited":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["message","status","sentAt","deliveredAt","readAt","playedAt","sentBy","origin","failureReason","forwarded","forwardedFrom","edited"],"description":"Entrega y lectura de un mensaje."},"MessageSender":{"anyOf":[{"type":"object","properties":{"kind":{"type":"string","const":"connection"},"jid":{"type":["string","null"]},"origin":{"type":"string","enum":["waqr","device"],"description":"`waqr`: enviado por la API o el panel; `device`: desde el teléfono."}},"required":["kind","jid","origin"]},{"type":"object","properties":{"kind":{"type":"string","enum":["contact","participant"]},"participantId":{"description":"Solo en grupos.","anyOf":[{"type":"string","pattern":"^gpt_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`gpt_…`)."},{"type":"null"}]},"contactId":{"anyOf":[{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},{"type":"null"}]},"jid":{"type":["string","null"]},"altJid":{"type":["string","null"]},"displayName":{"type":["string","null"]}},"required":["kind","contactId","jid","altJid","displayName"]}],"description":"Autor: la propia conexión (salientes) o el contacto/participante (entrantes)."},"PartnerCustomer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"externalId":{"description":"Id del cliente en tu sistema.","type":["string","null"]},"name":{"type":"string"},"country":{"type":"string"},"timezone":{"type":"string"},"status":{"type":"string","enum":["active","past_due","suspended","canceled","deleted"]},"connections":{"anyOf":[{"type":"integer"},{"type":"null"}],"description":"Conexiones del plan; null = sin tope numérico."},"graceUntil":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"reason":{"type":["string","null"]},"accessUrl":{"type":"string","description":"Dirección donde entra el cliente."},"usage":{"type":"object","properties":{"connections":{"type":"object","properties":{"used":{"type":"integer"},"limit":{"type":"integer"},"unlimited":{"type":"boolean","const":true}},"required":["used","limit"]}},"required":["connections"]},"owner":{"anyOf":[{"type":"object","properties":{"id":{"type":"string"},"email":{"type":"string"},"status":{"type":"string","enum":["active","invited"]}},"required":["id","email","status"]},{"type":"null"}],"description":"Owner del cliente (`id` vacío mientras la invitación está pendiente)."},"embed":{"type":"object","properties":{"engines":{"anyOf":[{"type":"array","items":{"type":"string","enum":["qr","waba"]}},{"type":"null"}],"description":"Null = los del revendedor."},"effectiveEngines":{"type":"array","items":{"type":"string","enum":["qr","waba"]}}},"required":["engines","effectiveEngines"]},"historyImport":{"type":"boolean"},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"deletedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","externalId","name","country","timezone","status","connections","graceUntil","reason","accessUrl","usage","owner","embed","historyImport","createdAt","updatedAt","deletedAt"],"description":"Cliente de un revendedor, identificado por tu `externalId`."},"PartnerFee":{"type":"object","properties":{"id":{"type":"string","pattern":"^fee_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`fee_…`)."},"period":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","description":"Primer día del mes que cubre la cuota (`YYYY-MM-DD`)."},"status":{"type":"string","enum":["pending","paid","void"],"description":"`pending` hasta el pago; con el corte vencido, el uso de tus clientes queda pausado."},"amountCents":{"type":"integer","description":"Importe en la unidad menor de la moneda."},"currency":{"type":"string"},"connections":{"type":"integer","description":"Conexiones cobradas en esta cuota."},"dueAt":{"anyOf":[{"type":"string","format":"date-time","description":"Vencimiento (día 1 del mes, en tu zona horaria)."},{"type":"null"}]},"cutAt":{"anyOf":[{"type":"string","format":"date-time","description":"Corte (día 2): sin pagar, el servicio de tus clientes se pausa."},{"type":"null"}]},"paidAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"paidVia":{"anyOf":[{"type":"string","enum":["paypal","manual"]},{"type":"null"}]},"createdAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["id","period","status","amountCents","currency","connections","dueAt","cutAt","paidAt","paidVia","createdAt"],"description":"Cuota mensual que pagas por las conexiones de tus clientes."},"PartnerFeeItem":{"type":"object","properties":{"id":{"type":"string","pattern":"^feei_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`feei_…`)."},"kind":{"type":"string","enum":["month","prorate"],"description":"`month` = mes completo; `prorate` = solo los días usados (alta a mitad de mes o baja)."},"startsOn":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","description":"Primer día cobrado."},"endsOn":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$","description":"Día siguiente al último cobrado (exclusivo)."},"days":{"type":"integer"},"amountCents":{"type":"integer"},"customer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"externalId":{"description":"Tu id del cliente.","type":["string","null"]},"name":{"type":["string","null"]}},"required":["id","externalId","name"]},"connection":{"type":"object","properties":{"id":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"label":{"type":["string","null"]},"phoneE164":{"type":["string","null"]},"engine":{"type":"string","enum":["evolution","waba"]},"deleted":{"type":"boolean"}},"required":["id","label","phoneE164","engine","deleted"]}},"required":["id","kind","startsOn","endsOn","days","amountCents","customer","connection"],"description":"Línea de una cuota: una conexión de un cliente y el tramo cobrado."},"PartnerPlan":{"type":"object","properties":{"id":{"type":"string","pattern":"^pplan_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`pplan_…`)."},"code":{"type":"string"},"name":{"type":"string"},"description":{"type":["string","null"]},"status":{"type":"string","enum":["draft","active","archived"]},"visibility":{"type":"string","enum":["listed","hidden"]},"price":{"anyOf":[{"type":"object","properties":{"amountCents":{"type":"integer"},"currency":{"type":"string"},"interval":{"type":"string","enum":["month","year"]}},"required":["amountCents","currency","interval"]},{"type":"null"}],"description":"Informativo: WAQR no cobra este precio."},"trialDays":{"type":"integer"},"entitlements":{"type":"array","items":{"type":"object","properties":{"feature":{"type":"string"},"quantity":{"type":"integer"},"enabled":{"type":"boolean"}},"required":["feature"]}},"version":{"type":"integer"},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","code","name","description","status","visibility","price","trialDays","entitlements","version","createdAt","updatedAt"],"description":"Plan que el partner ofrece a sus clientes."},"ResellerCustomer":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"name":{"type":"string"},"externalId":{"description":"Id del cliente en tu sistema.","type":["string","null"]},"status":{"type":"string","enum":["active","suspended","closed"]},"suspendedReason":{"anyOf":[{"type":"string","enum":["partner","partner_suspended","manual","billing","abuse"]},{"type":"null"}],"description":"`partner`: lo suspendiste tú; `partner_suspended`: por la suspensión del partner; el resto, WAQR."},"plan":{"type":"object","properties":{"status":{"type":"string","enum":["active","past_due","suspended","canceled"]},"connections":{"anyOf":[{"type":"integer"},{"type":"null"}]},"graceUntil":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"reason":{"type":["string","null"]},"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"historyImport":{"type":"boolean"}},"required":["status","connections","graceUntil","reason","updatedAt","historyImport"],"description":"Estado del plan del cliente según tu sistema."},"deletedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"isHouseAccount":{"type":"boolean","description":"Cuenta propia del partner."},"country":{"type":"string"},"timezone":{"type":"string"},"allocation":{"anyOf":[{"$ref":"#/components/schemas/CapacityAllocation"},{"type":"null"}]},"usage":{"type":"object","properties":{"connections":{"type":"object","properties":{"used":{"type":"integer"},"limit":{"type":"integer"},"unlimited":{"type":"boolean","const":true}},"required":["used","limit"]}},"required":["connections"]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","name","externalId","status","suspendedReason","plan","deletedAt","isHouseAccount","country","timezone","allocation","usage","createdAt"],"description":"Cliente del partner con su capacidad y su uso."},"ResellerCustomerDetail":{"type":"object","properties":{"id":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"name":{"type":"string"},"externalId":{"description":"Id del cliente en tu sistema.","type":["string","null"]},"status":{"type":"string","enum":["active","suspended","closed"]},"suspendedReason":{"anyOf":[{"type":"string","enum":["partner","partner_suspended","manual","billing","abuse"]},{"type":"null"}],"description":"`partner`: lo suspendiste tú; `partner_suspended`: por la suspensión del partner; el resto, WAQR."},"plan":{"type":"object","properties":{"status":{"type":"string","enum":["active","past_due","suspended","canceled"]},"connections":{"anyOf":[{"type":"integer"},{"type":"null"}]},"graceUntil":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"reason":{"type":["string","null"]},"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"historyImport":{"type":"boolean"}},"required":["status","connections","graceUntil","reason","updatedAt","historyImport"],"description":"Estado del plan del cliente según tu sistema."},"deletedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"isHouseAccount":{"type":"boolean","description":"Cuenta propia del partner."},"country":{"type":"string"},"timezone":{"type":"string"},"allocation":{"anyOf":[{"$ref":"#/components/schemas/CapacityAllocation"},{"type":"null"}]},"usage":{"type":"object","properties":{"connections":{"type":"object","properties":{"used":{"type":"integer"},"limit":{"type":"integer"},"unlimited":{"type":"boolean","const":true}},"required":["used","limit"]}},"required":["connections"]},"createdAt":{"type":"string","format":"date-time"},"owner":{"type":"object","properties":{"status":{"type":"string","enum":["active","invited","none"]},"emails":{"type":"array","items":{"type":"string"},"description":"Emails de los owners activos."},"pendingInvitation":{"anyOf":[{"type":"object","properties":{"email":{"type":"string"},"expiresAt":{"type":"string","format":"date-time"}},"required":["email","expiresAt"]},{"type":"null"}]}},"required":["status","emails","pendingInvitation"]}},"required":["id","name","externalId","status","suspendedReason","plan","deletedAt","isHouseAccount","country","timezone","allocation","usage","createdAt","owner"],"description":"Cliente del partner con su owner."},"SyncConflict":{"type":"object","properties":{"id":{"type":"string","pattern":"^csc_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`csc_…`)."},"contact":{"anyOf":[{"$ref":"#/components/schemas/ContactSummary"},{"type":"object","properties":{"id":{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."}},"required":["id"]}],"description":"El contacto; solo `id` si ya no está disponible."},"provider":{"type":"string","const":"google_contacts"},"field":{"type":"string","enum":["name","company","notes"]},"localValue":{"description":"Valor en WAQR.","type":["string","null"]},"remoteValue":{"description":"Valor en Google.","type":["string","null"]},"baseValue":{"description":"Último valor común.","type":["string","null"]},"detectedAt":{"type":"string","format":"date-time"},"resolvedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"resolution":{"anyOf":[{"type":"string","enum":["local","remote","custom","dismissed"]},{"type":"null"}],"description":"Cómo se resolvió; null si sigue abierto."}},"required":["id","contact","provider","field","localValue","remoteValue","baseValue","detectedAt","resolvedAt","resolution"],"description":"Conflicto de sincronización con Google Contacts: el mismo campo cambió en los dos lados."},"Template":{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"category":{"description":"`MARKETING`, `UTILITY` o `AUTHENTICATION`.","type":["string","null"]},"status":{"type":"string","description":"`APPROVED`, `PENDING`, `REJECTED`, `PAUSED`, `DISABLED`…"},"parameterFormat":{"description":"`POSITIONAL` o `NAMED`.","type":["string","null"]},"rejectedReason":{"type":["string","null"]},"components":{"type":"array","items":{},"description":"Componentes tal como los guarda Meta."},"previousCategory":{"type":["string","null"]},"categoryChangedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"statusChangedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"updatedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"headerFormat":{"anyOf":[{"type":"string","enum":["TEXT","IMAGE","VIDEO","DOCUMENT","LOCATION"]},{"type":"null"}]},"variables":{"type":"object","properties":{"header":{"type":"array","items":{"type":"string"}},"body":{"type":"array","items":{"type":"string"}},"buttons":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"type":{"type":"string"},"variables":{"type":"array","items":{"type":"string"}}},"required":["index","type","variables"]}}},"required":["header","body","buttons"],"description":"Variables que pide cada parte (`[\"1\",\"2\"]` o con nombre)."},"preview":{"type":"object","properties":{"header":{"type":["string","null"]},"body":{"type":["string","null"]},"footer":{"type":["string","null"]}},"required":["header","body","footer"]},"headerDefault":{"anyOf":[{"type":"object","properties":{"mimeType":{"type":"string"},"fileName":{"type":["string","null"]},"sizeBytes":{"type":"integer"},"setAt":{"type":"string","format":"date-time"}},"required":["mimeType","fileName","sizeBytes","setAt"]},{"type":"null"}],"description":"Archivo de cabecera que se usa si un envío no trae la cabecera multimedia."}},"required":["name","language","category","status","parameterFormat","rejectedReason","components","previousCategory","categoryChangedAt","statusChangedAt","createdAt","updatedAt","headerFormat","variables","preview","headerDefault"],"description":"Plantilla de WhatsApp oficial con su forma (cabecera, variables y vista previa).","examples":[{"name":"confirmacion_pedido","language":"es","category":"UTILITY","status":"APPROVED","parameterFormat":"POSITIONAL","rejectedReason":null,"components":[{"type":"HEADER","format":"IMAGE"},{"type":"BODY","text":"Hola {{1}}, tu pedido {{2}} está confirmado."},{"type":"FOOTER","text":"Tienda Ejemplo"}],"previousCategory":null,"categoryChangedAt":null,"statusChangedAt":"2026-11-28T12:00:00.000Z","createdAt":"2026-11-28T11:58:00.000Z","updatedAt":"2026-11-28T12:00:00.000Z","headerFormat":"IMAGE","variables":{"header":[],"body":["1","2"],"buttons":[]},"preview":{"header":"[imagen]","body":"Hola {{1}}, tu pedido {{2}} está confirmado.","footer":"Tienda Ejemplo"},"headerDefault":{"mimeType":"image/jpeg","fileName":"pedido.jpg","sizeBytes":48213,"setAt":"2026-11-28T12:05:00.000Z"}}]},"TemplateStats":{"type":"object","properties":{"range":{"type":"object","properties":{"from":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"to":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["from","to"]},"totals":{"type":"object","properties":{"sent":{"type":"integer"},"conversations":{"type":"integer"},"delivered":{"type":"integer"},"read":{"type":"integer"},"clicked":{"type":"integer","description":"Conversaciones que respondieron con un botón."},"replied":{"type":"integer"},"replied24h":{"type":"integer"},"replied7d":{"type":"integer","description":"Respondieron en 7 días (incluye las de 24 h)."},"repliedLater":{"type":"integer"},"noReply":{"type":"integer"},"failed":{"type":"integer"}},"required":["sent","conversations","delivered","read","clicked","replied","replied24h","replied7d","repliedLater","noReply","failed"]},"byTemplate":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"sent":{"type":"integer"},"replied":{"type":"integer"}},"required":["name","sent","replied"]},"description":"Envíos y respuestas por plantilla (sin el filtro `template`)."},"contacts":{"type":"object","properties":{"total":{"type":"integer"},"nextCursor":{"description":"Para `?contactsCursor=`; null en la última.","type":["string","null"]},"data":{"type":"array","items":{"type":"object","properties":{"contactId":{"anyOf":[{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},{"type":"null"}]},"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"name":{"type":"string"},"phone":{"type":["string","null"]},"templates":{"type":"array","items":{"type":"string"}},"sends":{"type":"integer"},"lastSentAt":{"type":"string","format":"date-time"},"response":{"type":"string","enum":["replied_24h","replied_7d","replied_later","no_reply"],"description":"Cuándo respondió el contacto tras la plantilla."},"clicked":{"type":"boolean"},"repliedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"windowOpen":{"type":"boolean","description":"La ventana de 24 h sigue abierta."}},"required":["contactId","conversationId","name","phone","templates","sends","lastSentAt","response","clicked","repliedAt","windowOpen"]}}},"required":["total","nextCursor","data"]},"sends":{"type":"object","properties":{"total":{"type":"integer"},"nextCursor":{"description":"Para `?sendsCursor=`; null en la última.","type":["string","null"]},"data":{"type":"array","items":{"type":"object","properties":{"messageId":{"type":"string","pattern":"^msg_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`msg_…`)."},"conversationId":{"type":"string","pattern":"^conv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conv_…`)."},"contact":{"type":"object","properties":{"contactId":{"anyOf":[{"type":"string","pattern":"^ct_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`ct_…`)."},{"type":"null"}]},"name":{"type":"string"},"phone":{"type":["string","null"]}},"required":["contactId","name","phone"]},"template":{"type":"string"},"language":{"type":["string","null"]},"sentAt":{"type":"string","format":"date-time"},"status":{"type":"string","description":"`pending`, `sent`, `delivered`, `read`, `played` o `failed`."},"response":{"type":"string","enum":["replied_24h","replied_7d","replied_later","no_reply"],"description":"Cuándo respondió el contacto tras la plantilla."}},"required":["messageId","conversationId","contact","template","language","sentAt","status","response"]}}},"required":["total","nextCursor","data"]},"truncated":{"type":"boolean","description":"Se alcanzó el máximo de envíos que se analizan."}},"required":["range","totals","byTemplate","contacts","sends","truncated"],"description":"Estadísticas de las plantillas enviadas por una conexión de WhatsApp oficial."},"Upload":{"type":"object","properties":{"id":{"type":"string","pattern":"^upl_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`upl_…`)."},"mimeType":{"type":"string"},"size":{"type":"integer"},"fileName":{"type":["string","null"]},"kind":{"type":"string","enum":["image","video","audio","document","sticker"]},"expiresAt":{"type":"string","format":"date-time"}},"required":["id","mimeType","size","fileName","kind","expiresAt"],"description":"Archivo subido para enviarlo después (`uploadId`)."},"WabaAccount":{"type":"object","properties":{"wabaId":{"type":"string"},"phoneNumberId":{"type":"string"},"displayPhone":{"type":["string","null"]},"verifiedName":{"type":["string","null"]},"qualityRating":{"type":["string","null"]},"messagingLimitTier":{"type":["string","null"]},"coexistence":{"type":"boolean"},"accountName":{"type":["string","null"]},"nameStatus":{"type":["string","null"]},"numberStatus":{"type":["string","null"]},"platformType":{"type":["string","null"]},"twoStepVerification":{"type":["boolean","null"]},"officialBusinessAccount":{"anyOf":[{"type":"string","enum":["not_requested","pending","approved","rejected"]},{"type":"null"}]},"lastSyncAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"demo":{"type":"boolean"},"managerUrl":{"type":["string","null"]},"platformNotify":{"type":"boolean"},"health":{"anyOf":[{"$ref":"#/components/schemas/WabaHealth"},{"type":"null"}]}},"required":["wabaId","phoneNumberId","displayPhone","verifiedName","qualityRating","messagingLimitTier","coexistence","accountName","nameStatus","numberStatus","platformType","twoStepVerification","officialBusinessAccount","lastSyncAt","demo","managerUrl","platformNotify","health"],"description":"Datos de Meta de una conexión de WhatsApp oficial (nunca el token)."},"WabaAnalytics":{"type":"object","properties":{"range":{"type":"object","properties":{"from":{"type":"string","format":"date","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$","description":"Primer día (zona horaria de la organización)."},"to":{"type":"string","format":"date","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$","description":"Último día, incluido."},"startsAt":{"type":"string","format":"date-time"},"endsAt":{"type":"string","format":"date-time"},"timezone":{"type":"string"},"days":{"type":"integer"}},"required":["from","to","startsAt","endsAt","timezone","days"],"description":"Periodo anterior de la misma duración."},"previousRange":{"type":"object","properties":{"from":{"type":"string","format":"date","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$","description":"Primer día (zona horaria de la organización)."},"to":{"type":"string","format":"date","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$","description":"Último día, incluido."},"startsAt":{"type":"string","format":"date-time"},"endsAt":{"type":"string","format":"date-time"},"timezone":{"type":"string"},"days":{"type":"integer"}},"required":["from","to","startsAt","endsAt","timezone","days"],"description":"Periodo anterior de la misma duración."},"currency":{"type":"string","const":"USD"},"connections":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"label":{"type":"string"},"status":{"type":"string","enum":["pending_qr","connecting","connected","disconnected","logged_out","banned","deleted"]},"phone":{"type":["string","null"]},"qualityRating":{"type":["string","null"]},"messagingLimitTier":{"type":["string","null"]},"demo":{"type":"boolean"}},"required":["id","label","status","phone","qualityRating","messagingLimitTier","demo"]}},"kpis":{"type":"object","properties":{"templatesSent":{"type":"integer"},"templatesDelivered":{"type":"integer"},"templatesRead":{"type":"integer"},"deliveryRate":{"description":"De 0 a 1; null sin envíos.","type":["number","null"]},"readRate":{"type":["number","null"]},"templateReplies":{"type":"integer"},"templateReplyRate":{"type":["number","null"]},"serviceWindowsOpened":{"type":"integer","description":"Ventanas de 24 h abiertas por los clientes."},"serviceMessagesSent":{"type":"integer"},"freeTemplates":{"type":"integer"},"windowsExpiredUnanswered":{"type":"integer"},"failed":{"type":"integer"},"failedByReason":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string"},"label":{"type":"string"},"count":{"type":"integer"}},"required":["code","label","count"]}}},"required":["templatesSent","templatesDelivered","templatesRead","deliveryRate","readRate","templateReplies","templateReplyRate","serviceWindowsOpened","serviceMessagesSent","freeTemplates","windowsExpiredUnanswered","failed","failedByReason"]},"previous":{"type":"object","properties":{"templatesSent":{"type":"integer"},"templatesDelivered":{"type":"integer"},"templatesRead":{"type":"integer"},"deliveryRate":{"description":"De 0 a 1; null sin envíos.","type":["number","null"]},"readRate":{"type":["number","null"]},"templateReplies":{"type":"integer"},"templateReplyRate":{"type":["number","null"]},"serviceWindowsOpened":{"type":"integer","description":"Ventanas de 24 h abiertas por los clientes."},"serviceMessagesSent":{"type":"integer"},"freeTemplates":{"type":"integer"},"windowsExpiredUnanswered":{"type":"integer"},"failed":{"type":"integer"},"estimatedTotalUsd":{"type":["number","null"]}},"required":["templatesSent","templatesDelivered","templatesRead","deliveryRate","readRate","templateReplies","templateReplyRate","serviceWindowsOpened","serviceMessagesSent","freeTemplates","windowsExpiredUnanswered","failed","estimatedTotalUsd"]},"cost":{"type":"object","properties":{"estimatedTotalUsd":{"description":"Null si falta la tarifa de alguna categoría.","type":["number","null"]},"byCategory":{"type":"array","items":{"type":"object","properties":{"category":{"type":"string","enum":["marketing","utility","authentication","service","uncategorized"]},"delivered":{"type":"integer"},"free":{"type":"integer"},"billable":{"type":"integer"},"unitPriceUsd":{"type":["number","null"]},"totalUsd":{"description":"Null si falta la tarifa de Meta.","type":["number","null"]}},"required":["category","delivered","free","billable","unitPriceUsd","totalUsd"]}},"missingRates":{"type":"boolean"},"disclaimer":{"type":"string"}},"required":["estimatedTotalUsd","byCategory","missingRates","disclaimer"]},"series":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string","format":"date","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"},"marketing":{"type":"integer"},"utility":{"type":"integer"},"authentication":{"type":"integer"},"service":{"type":"integer"},"costUsd":{"type":["number","null"]}},"required":["date","marketing","utility","authentication","service","costUsd"]}}},"required":["range","previousRange","currency","connections","kpis","previous","cost","series"],"description":"Métricas de WhatsApp oficial (plantillas, ventanas de atención) y costo estimado con las tarifas de Meta."},"WabaHealth":{"type":"object","properties":{"status":{"type":"string","enum":["ok","limited","payment_issue","blocked"]},"canSend":{"type":["string","null"]},"errors":{"type":"array","items":{"type":"object","properties":{"entity":{"type":"string"},"code":{"type":["string","null"]},"description":{"type":["string","null"]}},"required":["entity","code","description"]}},"since":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"checkedAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"advice":{"type":"string","enum":["send","reduce","pause"],"description":"`send`: normal; `reduce`: Meta limita, baja el ritmo; `pause`: no reintentes la cola hasta `retryAfter`."},"retryAfter":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]}},"required":["status","canSend","errors","since","checkedAt","advice","retryAfter"],"description":"Salud de la cuenta de WhatsApp oficial según Meta."},"WabaUsage":{"type":"object","properties":{"connectionId":{"type":"string","pattern":"^conn_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`conn_…`)."},"month":{"type":"string","description":"Mes `AAAA-MM` (UTC)."},"sentMessages":{"type":"integer"},"billableMessages":{"type":"integer"},"pricedMessages":{"type":"integer"},"estimatedTotalUsd":{"description":"Null si falta la tarifa de alguna categoría.","type":["number","null"]},"byCategory":{"type":"array","items":{"type":"object","properties":{"category":{"type":"string"},"delivered":{"type":"integer"},"free":{"type":"integer"},"billable":{"type":"integer"},"unitPriceUsd":{"type":["number","null"]},"totalUsd":{"type":["number","null"]}},"required":["category","delivered","free","billable","unitPriceUsd","totalUsd"]}},"alert":{"anyOf":[{"type":"object","properties":{"monthlyBillable":{"anyOf":[{"type":"integer"},{"type":"null"}]},"monthlyCostUsd":{"type":["number","null"]}},"required":["monthlyBillable","monthlyCostUsd"]},{"type":"null"}]},"disclaimer":{"type":"string"}},"required":["connectionId","month","sentMessages","billableMessages","pricedMessages","estimatedTotalUsd","byCategory","alert","disclaimer"],"description":"Consumo mensual de WhatsApp oficial y costo estimado."},"WebhookDelivery":{"type":"object","properties":{"id":{"type":"string","pattern":"^dlv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`dlv_…`)."},"webhookId":{"type":"string","description":"Valor de la cabecera `webhook-id` (igual en cada reintento)."},"endpointId":{"type":"string","pattern":"^whk_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`whk_…`)."},"eventType":{"type":"string"},"organizationId":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"state":{"type":"string","enum":["pending","delivering","succeeded","failed","exhausted","canceled"]},"attempts":{"type":"integer"},"replays":{"type":"integer"},"lastStatusCode":{"anyOf":[{"type":"integer"},{"type":"null"}]},"lastDurationMs":{"anyOf":[{"type":"integer"},{"type":"null"}]},"lastError":{"type":["string","null"]},"lastAttemptAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"nextAttemptAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"succeededAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","webhookId","endpointId","eventType","organizationId","state","attempts","replays","lastStatusCode","lastDurationMs","lastError","lastAttemptAt","nextAttemptAt","succeededAt","createdAt"],"description":"Entrega de un evento a un endpoint."},"WebhookDeliveryDetail":{"type":"object","properties":{"id":{"type":"string","pattern":"^dlv_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`dlv_…`)."},"webhookId":{"type":"string","description":"Valor de la cabecera `webhook-id` (igual en cada reintento)."},"endpointId":{"type":"string","pattern":"^whk_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`whk_…`)."},"eventType":{"type":"string"},"organizationId":{"type":"string","pattern":"^org_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`org_…`)."},"state":{"type":"string","enum":["pending","delivering","succeeded","failed","exhausted","canceled"]},"attempts":{"type":"integer"},"replays":{"type":"integer"},"lastStatusCode":{"anyOf":[{"type":"integer"},{"type":"null"}]},"lastDurationMs":{"anyOf":[{"type":"integer"},{"type":"null"}]},"lastError":{"type":["string","null"]},"lastAttemptAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"nextAttemptAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"succeededAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"createdAt":{"type":"string","format":"date-time"},"attemptLog":{"type":"array","items":{"type":"object","properties":{"attempt":{"type":"integer"},"outcome":{"type":"string","enum":["succeeded","failed","blocked"]},"statusCode":{"anyOf":[{"type":"integer"},{"type":"null"}]},"durationMs":{"type":"integer"},"error":{"type":["string","null"]},"nextAttemptAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"at":{"type":"string","format":"date-time"}},"required":["attempt","outcome","statusCode","durationMs","error","nextAttemptAt","at"]}}},"required":["id","webhookId","endpointId","eventType","organizationId","state","attempts","replays","lastStatusCode","lastDurationMs","lastError","lastAttemptAt","nextAttemptAt","succeededAt","createdAt","attemptLog"],"description":"Entrega con sus últimos 50 intentos."},"WebhookEndpoint":{"type":"object","properties":{"id":{"type":"string","pattern":"^whk_[0-9A-HJKMNP-TV-Z]{26}$","description":"Id público (`whk_…`)."},"url":{"type":"string"},"description":{"type":["string","null"]},"source":{"anyOf":[{"type":"string","enum":["n8n","zapier","make"]},{"type":"null"}]},"events":{"type":"array","items":{"type":"string"},"description":"Tipos de evento suscritos (`*` = todos)."},"status":{"type":"string","enum":["active","disabled"]},"apiVersion":{"type":"string"},"failureCount":{"type":"integer"},"failureSince":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastSuccessAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"lastFailureAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"disabledAt":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}]},"disabledReason":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","url","description","source","events","status","apiVersion","failureCount","failureSince","lastSuccessAt","lastFailureAt","disabledAt","disabledReason","createdAt","updatedAt"],"description":"Destino de webhooks (sin el secreto)."},"WelcomeSettings":{"type":"object","properties":{"enabled":{"type":"boolean"},"dailyCap":{"type":"integer","description":"Bienvenidas como máximo por día en la conexión."},"dedupeDays":{"type":"integer","description":"Días en que no se repite la bienvenida al mismo número."},"variants":{"type":"object","properties":{"default":{"type":"object","properties":{"text":{"type":"string","description":"Texto que se envía por QR (`{nombre}`, `{producto}`… se rellenan con el lead)."},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"params":{"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"],"description":"Variable del lead que va en ese parámetro de la plantilla."},"description":"Variable del lead de cada parámetro, en orden: el primero es `{{1}}`."}},"required":["name","language","params"]},{"type":"null"}],"description":"Plantilla aprobada que se envía en WhatsApp oficial; null si no hay."}},"required":["text","template"]},"form":{"type":"object","properties":{"text":{"type":"string","description":"Texto que se envía por QR (`{nombre}`, `{producto}`… se rellenan con el lead)."},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"params":{"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"],"description":"Variable del lead que va en ese parámetro de la plantilla."},"description":"Variable del lead de cada parámetro, en orden: el primero es `{{1}}`."}},"required":["name","language","params"]},{"type":"null"}],"description":"Plantilla aprobada que se envía en WhatsApp oficial; null si no hay."}},"required":["text","template"]},"product":{"type":"object","properties":{"text":{"type":"string","description":"Texto que se envía por QR (`{nombre}`, `{producto}`… se rellenan con el lead)."},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"params":{"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"],"description":"Variable del lead que va en ese parámetro de la plantilla."},"description":"Variable del lead de cada parámetro, en orden: el primero es `{{1}}`."}},"required":["name","language","params"]},{"type":"null"}],"description":"Plantilla aprobada que se envía en WhatsApp oficial; null si no hay."}},"required":["text","template"]},"page":{"type":"object","properties":{"text":{"type":"string","description":"Texto que se envía por QR (`{nombre}`, `{producto}`… se rellenan con el lead)."},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"params":{"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"],"description":"Variable del lead que va en ese parámetro de la plantilla."},"description":"Variable del lead de cada parámetro, en orden: el primero es `{{1}}`."}},"required":["name","language","params"]},{"type":"null"}],"description":"Plantilla aprobada que se envía en WhatsApp oficial; null si no hay."}},"required":["text","template"]}},"required":["default","form","product","page"],"description":"Mensaje según de dónde llega el lead: `default`, `form`, `product` y `page`."},"followUp":{"type":"object","properties":{"enabled":{"type":"boolean"},"afterHours":{"type":"number","description":"Horas sin respuesta antes del recordatorio."},"text":{"type":"string"},"template":{"anyOf":[{"type":"object","properties":{"name":{"type":"string"},"language":{"type":"string"},"params":{"type":"array","items":{"type":"string","enum":["nombre","producto","precio","pagina","tema","empresa"],"description":"Variable del lead que va en ese parámetro de la plantilla."},"description":"Variable del lead de cada parámetro, en orden: el primero es `{{1}}`."}},"required":["name","language","params"]},{"type":"null"}],"description":"Plantilla aprobada que se envía en WhatsApp oficial; null si no hay."}},"required":["enabled","afterHours","text","template"],"description":"Recordatorio si el lead no responde."},"engine":{"type":"string","enum":["evolution","waba"],"description":"`evolution` (QR): se envía `text`; `waba` (oficial): se envía `template`."}},"required":["enabled","dailyCap","dedupeDays","variants","followUp","engine"],"description":"Bienvenida automática de los leads web de una conexión (sin configurar, los valores por defecto)."}},"responses":{"Problem":{"description":"Error (RFC 9457).","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}}