{
  "openapi": "3.1.0",
  "info": {
    "title": "Octuvia API",
    "version": "0.1.0",
    "description": "API pública de Octuvia: cuentas WhatsApp, Messenger, Instagram y TikTok, mensajes, plantillas y webhooks. Base URL https://api.octuvia.com/v1.\n\nEspecificación generada automáticamente desde la documentación (https://docs.octuvia.com). Compatible con Postman, Insomnia y Bruno.\n\nVariables sugeridas:\n- `baseUrl`: https://api.octuvia.com/v1\n- `bearerToken`: octuvia_live_… (reemplaza por tu secret key real)",
    "contact": {
      "name": "Consultia Digital S.A.C.",
      "email": "soporte@octuvia.com",
      "url": "https://www.octuvia.com"
    }
  },
  "servers": [
    {
      "url": "https://api.octuvia.com/v1",
      "description": "api.octuvia.com/v1"
    }
  ],
  "tags": [
    {
      "name": "Accounts",
      "description": "Endpoints de /accounts"
    },
    {
      "name": "Conversations",
      "description": "Endpoints de /conversations"
    },
    {
      "name": "Events",
      "description": "Endpoints de /events"
    },
    {
      "name": "Messages",
      "description": "Endpoints de /messages"
    },
    {
      "name": "Webhook Deliveries",
      "description": "Endpoints de /webhook-deliveries"
    },
    {
      "name": "Webhook Endpoints",
      "description": "Endpoints de /webhook-endpoints"
    },
    {
      "name": "Whatsapp",
      "description": "Endpoints de /whatsapp"
    }
  ],
  "paths": {
    "/accounts": {
      "get": {
        "operationId": "communications-whatsapp-get-accounts",
        "summary": "Listar números",
        "description": "Lista cuentas conectadas (números WhatsApp, páginas Messenger, etc.). Respuesta slim: identidad + bloque de plataforma.\n\nFiltra por `platform` (p. ej. whatsapp). El detalle completo está en GET /accounts/{id}.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "object": "account",
                      "id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "platform": "whatsapp",
                      "name": "Clínica Sonrisa — Ventas",
                      "status": "active",
                      "whatsapp": {
                        "phone_number": "+51987654321",
                        "waba_id": "102990123456789",
                        "phone_number_id": "106540352242922",
                        "quality_rating": "GREEN"
                      }
                    }
                  ],
                  "has_more": false,
                  "next_cursor": null
                }
              }
            }
          },
          "401": {
            "description": "Credenciales inválidas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "authentication_error",
                    "code": "UNAUTHORIZED",
                    "message": "Missing or invalid credentials.",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "platform",
            "in": "query",
            "required": false,
            "description": "whatsapp | messenger | instagram | tiktok",
            "schema": {
              "description": "whatsapp | messenger | instagram | tiktok",
              "example": "whatsapp",
              "type": "string"
            },
            "example": "whatsapp"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "Filtrar por estado (active, disconnected, …).",
            "schema": {
              "description": "Filtrar por estado (active, disconnected, …).",
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Cursor de paginación.",
            "schema": {
              "description": "Cursor de paginación.",
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Tamaño de página (1–100, default 50).",
            "schema": {
              "description": "Tamaño de página (1–100, default 50).",
              "example": 50,
              "type": "integer"
            },
            "example": 50
          }
        ]
      }
    },
    "/accounts/{account_id}/reconnect": {
      "post": {
        "operationId": "communications-whatsapp-connection-post-account-reconnect",
        "summary": "Reconectar número",
        "description": "Para un número ya conectado (`acc_…`) que dejó de funcionar o pide reautorización: reengancha el número con Meta sin crear otra cuenta.\n\nSin body. Path: `account_id` del número (`acc_…`), no del workspace. La API key identifica el workspace. Recomendado `Idempotency-Key`.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "account_reconnect",
                  "ok": true,
                  "verified": true,
                  "waba_id": "102290129340398",
                  "phone_number_id": "106540352242922",
                  "warnings": [],
                  "steps": {
                    "permanentTokenRefreshed": true,
                    "webhookSubscribed": true,
                    "phoneRegistered": true,
                    "throughputSynced": true
                  },
                  "account": {
                    "object": "account",
                    "id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "platform": "whatsapp",
                    "name": "Ventas",
                    "status": "active",
                    "whatsapp": {
                      "phone_number": "+51987654321",
                      "waba_id": "102290129340398",
                      "phone_number_id": "106540352242922",
                      "quality_rating": "GREEN"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          },
          "404": {
            "description": "Account no encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "ACCOUNT_NOT_FOUND",
                    "message": "No existe el account indicado.",
                    "param": "account_id",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "Id del número en Octuvia (`acc_…`).",
            "schema": {
              "type": "string",
              "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "account_id": {
                    "description": "Id del número en Octuvia (`acc_…`).",
                    "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  }
                },
                "required": [
                  "account_id"
                ]
              }
            }
          }
        }
      }
    },
    "/accounts/{account_id}/templates": {
      "get": {
        "operationId": "communications-whatsapp-templates-get-account-templates",
        "summary": "Listar plantillas",
        "description": "Lista las plantillas del número conectado. Son del WABA: todos los números del mismo WABA ven las mismas. Se sincronizan al listar.\n\nPath: `account_id` del número (`acc_…`). La API key identifica el workspace. Filtros opcionales por query.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "object": "template",
                      "id": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "name": "pedido_enviado",
                      "language": "es",
                      "category": "UTILITY",
                      "status": "APPROVED",
                      "rejection_reason": null,
                      "quality_score": "GREEN",
                      "components": [
                        {
                          "type": "BODY",
                          "text": "Hola {{1}}, tu pedido {{2}} ha salido."
                        }
                      ],
                      "created_at": "2026-03-26T12:00:00Z",
                      "updated_at": "2026-03-26T12:10:00Z"
                    }
                  ],
                  "has_more": false,
                  "next_cursor": null
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "Id del número (`acc_…`).",
            "schema": {
              "type": "string",
              "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ]
      },
      "post": {
        "operationId": "communications-whatsapp-templates-post-account-templates",
        "summary": "Crear plantilla",
        "description": "Crea una plantilla y la manda a revisión. Queda en `PENDING` hasta que se apruebe o rechace.\n\nPath: `account_id` (`acc_…`). Recomendado `Idempotency-Key`. Si el texto tiene `{{1}}`, `{{2}}`… debes mandar `example` con samples. Nombre ya usado en ese idioma → 409.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "template",
                  "id": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "name": "pedido_enviado",
                  "language": "es",
                  "category": "UTILITY",
                  "status": "PENDING",
                  "rejection_reason": null,
                  "components": [
                    {
                      "type": "BODY",
                      "text": "Hola {{1}}, tu pedido {{2}} ha salido.",
                      "example": {
                        "body_text": [
                          [
                            "María",
                            "ORD-123"
                          ]
                        ]
                      }
                    }
                  ],
                  "created_at": "2026-03-26T12:00:00Z",
                  "updated_at": "2026-03-26T12:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          },
          "409": {
            "description": "Nombre ya usado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "TEMPLATE_NAME_TAKEN",
                    "message": "Ya existe una plantilla con ese name e language.",
                    "param": "name",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Plantilla inválida",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "TEMPLATE_INVALID",
                    "message": "El contenido de la plantilla no fue aceptado.",
                    "param": "components",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "Id del número (`acc_…`) en la ruta.",
            "schema": {
              "type": "string",
              "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "account_id": {
                    "description": "Id del número (`acc_…`) en la ruta.",
                    "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  },
                  "name": {
                    "description": "Nombre en snake_case (minúsculas, números, `_`).",
                    "example": "pedido_enviado",
                    "type": "string"
                  },
                  "language": {
                    "description": "Código de idioma (ej. `es`, `en_US`).",
                    "example": "es",
                    "type": "string"
                  },
                  "category": {
                    "description": "`MARKETING` | `UTILITY` | `AUTHENTICATION`.",
                    "example": "UTILITY",
                    "type": "string"
                  },
                  "components": {
                    "description": "Piezas de la plantilla: `HEADER`, `BODY`, `FOOTER`, `BUTTONS`. Con variables, incluye `example`.",
                    "type": "array",
                    "items": {}
                  }
                },
                "required": [
                  "account_id",
                  "name",
                  "language",
                  "category",
                  "components"
                ]
              },
              "example": {
                "name": "pedido_enviado",
                "language": "es",
                "category": "UTILITY",
                "components": [
                  {
                    "type": "BODY",
                    "text": "Hola {{1}}, tu pedido {{2}} ha salido.",
                    "example": {
                      "body_text": [
                        [
                          "María",
                          "ORD-123"
                        ]
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/accounts/{account_id}/whatsapp/profile": {
      "post": {
        "operationId": "communications-whatsapp-settings-post-whatsapp-profile",
        "summary": "Actualizar perfil WhatsApp",
        "description": "Actualiza about, description, email, vertical, websites y address en Meta.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "whatsapp_business_profile",
                  "profile": {
                    "about": "Soporte 24/7",
                    "vertical": "OTHER"
                  }
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "Parámetro de ruta account_id",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "about": {
                    "description": "Máx. 139 caracteres.",
                    "type": "string"
                  },
                  "description": {
                    "description": "Máx. 512 caracteres.",
                    "type": "string"
                  },
                  "email": {
                    "description": "Email de contacto.",
                    "type": "string"
                  },
                  "vertical": {
                    "description": "Categoría Meta (OTHER, RETAIL, …).",
                    "type": "string"
                  },
                  "websites": {
                    "description": "Hasta 2 URLs http(s).",
                    "type": "array",
                    "items": {}
                  },
                  "address": {
                    "description": "Dirección del negocio.",
                    "type": "string"
                  }
                }
              },
              "example": {
                "about": "Soporte 24/7",
                "vertical": "OTHER"
              }
            }
          }
        }
      }
    },
    "/accounts/{account_id}/whatsapp/settings": {
      "get": {
        "operationId": "communications-whatsapp-settings-get-whatsapp-settings",
        "summary": "Leer settings WhatsApp",
        "description": "Perfil de negocio, métricas del número y datos del WABA.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "whatsapp_settings",
                  "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "profile": {
                    "about": "Soporte 24/7",
                    "email": "contacto@empresa.com",
                    "vertical": "OTHER"
                  },
                  "number": {
                    "phone_number": "+51987654321",
                    "quality_rating": "GREEN",
                    "messaging_limit_tier": "TIER_1K"
                  },
                  "business": {
                    "waba_id": "1654482466166537",
                    "timezone_id": "55"
                  }
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "Parámetro de ruta account_id",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/accounts/{account_id}/whatsapp/timezone": {
      "post": {
        "operationId": "communications-whatsapp-settings-post-whatsapp-timezone",
        "summary": "Actualizar zona horaria",
        "description": "Cambia el timezone_id numérico del WABA en Meta (día analítico). Meta puede rechazarlo si hay línea de crédito.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "whatsapp_business_account",
                  "business": {
                    "waba_id": "1654482466166537",
                    "timezone_id": "55"
                  }
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "Parámetro de ruta account_id",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "timezone_id": {
                    "description": "Id numérico Meta (ej. 55 = Europe/Madrid).",
                    "example": 55,
                    "type": "string"
                  }
                },
                "required": [
                  "timezone_id"
                ]
              },
              "example": {
                "timezone_id": "55"
              }
            }
          }
        }
      }
    },
    "/accounts/whatsapp/credentials": {
      "post": {
        "operationId": "communications-whatsapp-connection-post-whatsapp-credentials",
        "summary": "Conectar con credenciales",
        "description": "Traes tu propia app Meta (BYO): WABA, número, token de System User y app_secret. Octuvia valida, engancha el webhook del número y crea el account. Solo keys live.\n\nAlternativa al connect link cuando ya tienes app + WABA. La API key identifica el workspace. Recomendado `Idempotency-Key`. El token necesita `whatsapp_business_management` y `whatsapp_business_messaging`.",
        "tags": [
          "Accounts"
        ],
        "responses": {
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "account",
                  "id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "platform": "whatsapp",
                  "name": "Ventas",
                  "status": "active",
                  "connection_method": "credentials",
                  "whatsapp": {
                    "phone_number": "+51987654321",
                    "verified_name": "Clínica Sonrisa",
                    "waba_id": "102290129340398",
                    "phone_number_id": "106540352242922",
                    "quality_rating": "GREEN"
                  },
                  "connected_at": "2026-03-26T12:05:00Z",
                  "created_at": "2026-03-26T12:05:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          },
          "403": {
            "description": "Solo live",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "permission_error",
                    "code": "LIVE_MODE_REQUIRED",
                    "message": "Conectar con credenciales solo funciona con keys live.",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Número ya conectado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "PHONE_NUMBER_ALREADY_CONNECTED",
                    "message": "Este phone_number_id ya está conectado en otra cuenta.",
                    "param": "phone_number_id",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "waba_id": {
                    "description": "ID del WhatsApp Business Account en Meta.",
                    "example": 102290129340398,
                    "type": "string"
                  },
                  "phone_number_id": {
                    "description": "Phone number ID de Graph (debe pertenecer a ese WABA).",
                    "example": 106540352242922,
                    "type": "string"
                  },
                  "access_token": {
                    "description": "Token de System User. Se guarda cifrado; nunca se devuelve.",
                    "type": "string"
                  },
                  "app_secret": {
                    "description": "App secret de tu app Meta (firma de webhooks). Se guarda cifrado; nunca se devuelve.",
                    "type": "string"
                  },
                  "pin": {
                    "description": "6 dígitos. Si el número aún no está en Cloud API, lo registra con este PIN. Sin `pin`, el número ya debe estar en Cloud API.",
                    "type": "string"
                  },
                  "name": {
                    "description": "Nombre interno en Octuvia (ej. Ventas).",
                    "example": "Ventas",
                    "type": "string"
                  },
                  "reference": {
                    "description": "Id libre tuyo (CRM). Vuelve en el account y en `account.connected`.",
                    "type": "string"
                  }
                },
                "required": [
                  "waba_id",
                  "phone_number_id",
                  "access_token",
                  "app_secret"
                ]
              },
              "example": {
                "waba_id": "102290129340398",
                "phone_number_id": "106540352242922",
                "access_token": "EAAB…",
                "app_secret": "…",
                "name": "Ventas"
              }
            }
          }
        }
      }
    },
    "/conversations": {
      "get": {
        "operationId": "communications-whatsapp-conversations-get-conversations",
        "summary": "Listar conversaciones",
        "description": "Bandeja del workspace: de la actividad más reciente a la más antigua.\n\nSin body. Filtra con query. Cada ítem trae `window_expires_at` (ventana 24 h) y el contacto.",
        "tags": [
          "Conversations"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "has_more": false,
                  "next_cursor": null,
                  "data": [
                    {
                      "object": "conversation",
                      "id": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "platform": "whatsapp",
                      "contact": {
                        "id": "+51987654321",
                        "name": "Ana Pérez",
                        "whatsapp": {
                          "wa_id": "51987654321"
                        }
                      },
                      "status": "open",
                      "unread_count": 1,
                      "last_message_at": "2026-10-28T12:00:00Z",
                      "last_inbound_at": "2026-10-28T12:00:00Z",
                      "window_expires_at": "2026-10-29T12:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "account_id",
            "in": "query",
            "required": false,
            "description": "Solo hilos de este número (`acc_…`).",
            "schema": {
              "description": "Solo hilos de este número (`acc_…`).",
              "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
              "type": "string"
            },
            "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "`open` | `closed`.",
            "schema": {
              "description": "`open` | `closed`.",
              "example": "open",
              "type": "string"
            },
            "example": "open"
          },
          {
            "name": "contact_id",
            "in": "query",
            "required": false,
            "description": "Identificador nativo del contacto (E.164 en WhatsApp).",
            "schema": {
              "description": "Identificador nativo del contacto (E.164 en WhatsApp).",
              "example": "+51987654321",
              "type": "string"
            },
            "example": "+51987654321"
          },
          {
            "name": "updated_after",
            "in": "query",
            "required": false,
            "description": "ISO-8601: solo conversaciones actualizadas después de esta fecha.",
            "schema": {
              "description": "ISO-8601: solo conversaciones actualizadas después de esta fecha.",
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Tamaño de página (1–100, default 50).",
            "schema": {
              "description": "Tamaño de página (1–100, default 50).",
              "example": 50,
              "type": "integer"
            },
            "example": 50
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Cursor de paginación (`next_cursor` de la respuesta anterior).",
            "schema": {
              "description": "Cursor de paginación (`next_cursor` de la respuesta anterior).",
              "type": "string"
            }
          }
        ]
      }
    },
    "/conversations/{conversation_id}/messages": {
      "get": {
        "operationId": "communications-whatsapp-conversations-get-conversation-messages",
        "summary": "Mensajes del hilo",
        "description": "Historial de una conversación (más reciente primero).\n\nSin body. Path: `conversation_id` (`conv_…`). Query: `limit`, `cursor`.",
        "tags": [
          "Conversations"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "has_more": false,
                  "next_cursor": null,
                  "data": [
                    {
                      "object": "message",
                      "id": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "conversation_id": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "platform": "whatsapp",
                      "direction": "inbound",
                      "type": "text",
                      "content": {
                        "text": {
                          "body": "Hola, quiero info"
                        }
                      },
                      "status": "delivered",
                      "reactions": [],
                      "created_at": "2026-10-28T12:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Tamaño de página (1–100, default 50).",
            "schema": {
              "description": "Tamaño de página (1–100, default 50).",
              "example": 50,
              "type": "integer"
            },
            "example": 50
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Cursor de paginación.",
            "schema": {
              "description": "Cursor de paginación.",
              "type": "string"
            }
          },
          {
            "name": "conversation_id",
            "in": "path",
            "required": true,
            "description": "Id del hilo en la ruta (`conv_…`).",
            "schema": {
              "type": "string",
              "example": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ]
      },
      "post": {
        "operationId": "communications-whatsapp-conversations-post-conversation-template",
        "summary": "Enviar plantilla",
        "description": "Envía una plantilla aprobada en un hilo existente. Funciona con la ventana 24 h cerrada.\n\nJSON con `type: template` + `template`. Preferido: `template.id` (`tpl_…`). Alternativa: `name` + `language`. El `account_id` y el `to` salen de la conversación. Debe estar `APPROVED`.",
        "tags": [
          "Conversations"
        ],
        "responses": {
          "202": {
            "description": "202",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "message",
                  "id": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V8",
                  "conversation_id": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "direction": "outbound",
                  "type": "template",
                  "status": "queued",
                  "created_at": "2026-10-28T12:05:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          },
          "404": {
            "description": "Plantilla no encontrada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "TEMPLATE_NOT_FOUND",
                    "message": "No existe esa plantilla en el número.",
                    "param": "template.name",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Plantilla no aprobada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "TEMPLATE_NOT_APPROVED",
                    "message": "La plantilla no está aprobada.",
                    "param": "template.name",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "conversation_id",
            "in": "path",
            "required": true,
            "description": "Id del hilo (`conv_…`) en la ruta.",
            "schema": {
              "type": "string",
              "example": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "conversation_id": {
                    "description": "Id del hilo (`conv_…`) en la ruta.",
                    "example": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  },
                  "type": {
                    "description": "Debe ser `template`.",
                    "example": "template",
                    "type": "string"
                  },
                  "template": {
                    "description": "Plantilla a enviar.",
                    "type": "object",
                    "properties": {
                      "id": {
                        "description": "Preferido. `tpl_…` de GET /accounts/{id}/templates.",
                        "example": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                        "type": "string"
                      },
                      "name": {
                        "description": "Alternativa a `id` (junto con `language`).",
                        "example": "pedido_enviado",
                        "type": "string"
                      },
                      "language": {
                        "description": "Obligatorio si no mandas `id`.",
                        "example": "es",
                        "type": "string"
                      },
                      "body_parameters": {
                        "description": "Valores de `{{1}}`, `{{2}}`… del BODY, en orden.",
                        "type": "array",
                        "items": {}
                      },
                      "header_parameters": {
                        "description": "Parámetros del HEADER si aplica.",
                        "type": "array",
                        "items": {}
                      },
                      "button_parameters": {
                        "description": "Parámetros de botones dinámicos.",
                        "type": "array",
                        "items": {}
                      }
                    },
                    "required": [
                      "id"
                    ]
                  },
                  "reply_to": {
                    "description": "Opcional. `msg_…` a citar.",
                    "type": "string"
                  }
                },
                "required": [
                  "conversation_id",
                  "type",
                  "template"
                ]
              },
              "example": {
                "type": "template",
                "template": {
                  "id": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "body_parameters": [
                    "Ana",
                    "1042"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "webhooks-get-events",
        "summary": "Listar eventos",
        "description": "Log de eventos del workspace (más reciente primero). Útil si tu endpoint estuvo caído: reconciliás y reintentas entregas.",
        "tags": [
          "Events"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "object": "event",
                      "id": "evt_01M8WF7BMSW8W9Y51TK72HS3A9",
                      "type": "message.delivered",
                      "api_version": "v1",
                      "created_at": "2026-12-03T22:33:12Z",
                      "livemode": true,
                      "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "resource_id": "msg_01J8…"
                    }
                  ],
                  "has_more": true,
                  "next_cursor": "evt_…"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/events/{event_id}/deliveries": {
      "get": {
        "operationId": "webhooks-get-event-deliveries",
        "summary": "Entregas de un evento",
        "description": "Intentos de entrega de un evento a tus endpoints (status, intentos, HTTP).",
        "tags": [
          "Events"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "object": "webhook_delivery",
                      "id": "whd_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "event_id": "evt_01M8WF7BMSW8W9Y51TK72HS3A9",
                      "event_type": "message.delivered",
                      "webhook_endpoint_id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "status": "delivered",
                      "attempts": 1,
                      "http_status": 200,
                      "created_at": "2026-12-03T22:33:12Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "event_id",
            "in": "path",
            "required": true,
            "description": "Id `evt_…`.",
            "schema": {
              "type": "string",
              "example": "evt_01M8WF7BMSW8W9Y51TK72HS3A9"
            }
          }
        ]
      }
    },
    "/messages": {
      "post": {
        "operationId": "communications-whatsapp-messages-post-messages",
        "summary": "Enviar mensaje",
        "description": "Texto (ventana 24 h) o plantilla. Usa el account_id del número conectado. La conversación se crea al vuelo.\n\nBody JSON: `account_id` + `to` + `type` + objeto del tipo. También admite multipart (`file`) para media. Asíncrono: 202 `queued`. Recomendado `Idempotency-Key`.",
        "tags": [
          "Messages"
        ],
        "responses": {
          "202": {
            "description": "202",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "message",
                  "id": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "conversation_id": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "direction": "outbound",
                  "type": "template",
                  "status": "queued",
                  "created_at": "2026-10-28T12:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "account_id": {
                    "description": "Cuenta Octuvia del número (`acc_…`).",
                    "example": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  },
                  "to": {
                    "description": "Destinatario E.164.",
                    "example": "+51987654321",
                    "type": "string"
                  },
                  "type": {
                    "description": "`text` | `template` | `image` | `video` | `audio` | `document` | `sticker` | `location` | `contacts` | `interactive`.",
                    "example": "template",
                    "type": "string"
                  },
                  "text": {
                    "description": "Si `type=text`.",
                    "type": "object",
                    "properties": {
                      "body": {
                        "description": "Texto. Máx. 4096.",
                        "type": "string"
                      },
                      "preview_url": {
                        "description": "Preview de links. Default `true`.",
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "body"
                    ]
                  },
                  "template": {
                    "description": "Si `type=template` (fuera de ventana 24 h).",
                    "type": "object",
                    "properties": {
                      "id": {
                        "description": "Preferido. `tpl_…`.",
                        "example": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                        "type": "string"
                      },
                      "name": {
                        "description": "Alternativa a `id` (con `language`).",
                        "example": "pedido_enviado",
                        "type": "string"
                      },
                      "language": {
                        "description": "Obligatorio si no mandas `id`.",
                        "example": "es",
                        "type": "string"
                      },
                      "body_parameters": {
                        "description": "Valores de `{{1}}`, `{{2}}`… del BODY.",
                        "type": "array",
                        "items": {}
                      },
                      "header_parameters": {
                        "description": "Parámetros del encabezado (texto o media).",
                        "type": "array",
                        "items": {}
                      }
                    }
                  },
                  "image": {
                    "description": "Si `type=image`: `{ url }` o `{ media_id }` (+ `caption?`).",
                    "type": "object",
                    "additionalProperties": true
                  },
                  "reply_to": {
                    "description": "`msg_…` a citar (opcional).",
                    "type": "string"
                  },
                  "metadata": {
                    "description": "Metadata libre (string→string).",
                    "type": "object",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "account_id",
                  "to",
                  "type"
                ]
              },
              "example": {
                "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                "to": "+51987654321",
                "type": "template",
                "template": {
                  "id": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "body_parameters": [
                    "Ana",
                    "1042"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/messages/{message_id}/reactions": {
      "delete": {
        "operationId": "communications-whatsapp-conversations-delete-message-reactions",
        "summary": "Quitar reacción",
        "description": "Elimina tu reacción saliente del mensaje.\n\nSin body. Path: `message_id` (`msg_…`). Solo quita tu reacción `outbound`.",
        "tags": [
          "Messages"
        ],
        "responses": {
          "202": {
            "description": "202",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "message",
                  "id": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "reactions": []
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "message_id",
            "in": "path",
            "required": true,
            "description": "Mensaje del que quitas la reacción (`msg_…`).",
            "schema": {
              "type": "string",
              "example": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ]
      },
      "post": {
        "operationId": "communications-whatsapp-conversations-post-message-reactions",
        "summary": "Reaccionar a un mensaje",
        "description": "Un emoji por mensaje; otro lo reemplaza. Necesita ventana de 24 h.\n\nPath: `message_id` (`msg_…`). Body JSON con `emoji`. Responde el mensaje con `reactions` actualizado; el envío a WhatsApp va en la cola del hilo.",
        "tags": [
          "Messages"
        ],
        "responses": {
          "202": {
            "description": "202",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "message",
                  "id": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "reactions": [
                    {
                      "emoji": "👍",
                      "direction": "outbound",
                      "reacted_at": "2026-10-28T12:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "message_id",
            "in": "path",
            "required": true,
            "description": "Mensaje a reaccionar (`msg_…`) en la ruta.",
            "schema": {
              "type": "string",
              "example": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message_id": {
                    "description": "Mensaje a reaccionar (`msg_…`) en la ruta.",
                    "example": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  },
                  "emoji": {
                    "description": "Emoji Unicode (uno solo).",
                    "example": "👍",
                    "type": "string"
                  }
                },
                "required": [
                  "message_id",
                  "emoji"
                ]
              },
              "example": {
                "emoji": "👍"
              }
            }
          }
        }
      }
    },
    "/webhook-deliveries/{delivery_id}/retry": {
      "post": {
        "operationId": "webhooks-post-retry-delivery",
        "summary": "Reintentar entrega",
        "description": "Reencola una entrega para envío inmediato, incluso si quedó dead. Idempotency-Key recomendado.",
        "tags": [
          "Webhook Deliveries"
        ],
        "responses": {
          "202": {
            "description": "202",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "webhook_delivery",
                  "id": "whd_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "event_id": "evt_01M8WF7BMSW8W9Y51TK72HS3A9",
                  "event_type": "message.delivered",
                  "webhook_endpoint_id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "status": "pending",
                  "attempts": 5,
                  "created_at": "2026-12-03T22:33:12Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "delivery_id",
            "in": "path",
            "required": true,
            "description": "Id `whd_…` (desde GET /events/{id}/deliveries).",
            "schema": {
              "type": "string",
              "example": "whd_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "delivery_id": {
                    "description": "Id `whd_…` (desde GET /events/{id}/deliveries).",
                    "example": "whd_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  }
                },
                "required": [
                  "delivery_id"
                ]
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints": {
      "get": {
        "operationId": "webhooks-get-webhook-endpoints",
        "summary": "Listar endpoints",
        "description": "Lista los webhook endpoints del workspace (modo de la API key).",
        "tags": [
          "Webhook Endpoints"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "object": "webhook_endpoint",
                      "id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                      "url": "https://api.tuapp.com/octuvia/webhooks",
                      "description": "Producción",
                      "events": [
                        "message.*",
                        "account.*",
                        "whatsapp.*"
                      ],
                      "platforms": [],
                      "profile_ids": [],
                      "account_ids": [],
                      "status": "enabled",
                      "livemode": true,
                      "created_at": "2026-12-01T10:00:00Z"
                    }
                  ],
                  "has_more": false,
                  "next_cursor": null
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      },
      "post": {
        "operationId": "webhooks-post-webhook-endpoints",
        "summary": "Crear endpoint",
        "description": "Registra una URL HTTPS y los eventos a recibir. El signing_secret (whsec_…) solo se muestra aquí y al rotar: guárdalo.\n\nRecomendado `Idempotency-Key`. La URL debe ser HTTPS pública (accesible desde internet).",
        "tags": [
          "Webhook Endpoints"
        ],
        "responses": {
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "webhook_endpoint",
                  "id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "url": "https://api.tuapp.com/octuvia/webhooks",
                  "description": "Producción",
                  "events": [
                    "message.*",
                    "account.*",
                    "whatsapp.*"
                  ],
                  "platforms": [],
                  "profile_ids": [],
                  "account_ids": [],
                  "status": "enabled",
                  "livemode": true,
                  "signing_secret": "whsec_a1b2c3d4e5f6…",
                  "created_at": "2026-12-03T08:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "description": "URL HTTPS de tu receptor.",
                    "example": "https://api.tuapp.com/octuvia/webhooks",
                    "type": "string"
                  },
                  "events": {
                    "description": "Tipos exactos, familias (`message.*`, `whatsapp.*`) o `[\"*\"]`. Ver [catálogo](/webhooks).",
                    "example": [
                      "message.*",
                      "account.*",
                      "whatsapp.*"
                    ],
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "description": {
                    "description": "Etiqueta libre.",
                    "example": "Producción",
                    "type": "string"
                  },
                  "platforms": {
                    "description": "Filtro de canal. Vacío = todos. Hoy: `whatsapp`.",
                    "type": "array",
                    "items": {}
                  },
                  "profile_ids": {
                    "description": "Vacío = todos los profiles.",
                    "type": "array",
                    "items": {}
                  },
                  "account_ids": {
                    "description": "Solo eventos de estos `acc_…`. Vacío = todos.",
                    "type": "array",
                    "items": {}
                  }
                },
                "required": [
                  "url",
                  "events"
                ]
              },
              "example": {
                "url": "https://api.tuapp.com/octuvia/webhooks",
                "description": "Producción",
                "events": [
                  "message.*",
                  "account.*",
                  "whatsapp.*"
                ]
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{webhook_endpoint_id}": {
      "delete": {
        "operationId": "webhooks-delete-webhook-endpoint",
        "summary": "Eliminar endpoint",
        "description": "Borra el endpoint. Las entregas pendientes a esa URL se cancelan.",
        "tags": [
          "Webhook Endpoints"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "webhook_endpoint",
                  "id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "deleted": true
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "webhook_endpoint_id",
            "in": "path",
            "required": true,
            "description": "Id `we_…`.",
            "schema": {
              "type": "string",
              "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ]
      },
      "patch": {
        "operationId": "webhooks-patch-webhook-endpoint",
        "summary": "Actualizar endpoint",
        "description": "Cambia URL, eventos, filtros o status (enabled / disabled). Úsalo también para reactivar uno en disabled_by_failures.",
        "tags": [
          "Webhook Endpoints"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "webhook_endpoint",
                  "id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "url": "https://api.tuapp.com/octuvia/webhooks",
                  "events": [
                    "message.*",
                    "whatsapp.account.*",
                    "whatsapp.number.*"
                  ],
                  "status": "enabled",
                  "livemode": true,
                  "created_at": "2026-12-01T10:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "webhook_endpoint_id",
            "in": "path",
            "required": true,
            "description": "Id `we_…`.",
            "schema": {
              "type": "string",
              "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "webhook_endpoint_id": {
                    "description": "Id `we_…`.",
                    "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  },
                  "url": {
                    "description": "Nueva URL HTTPS.",
                    "type": "string"
                  },
                  "events": {
                    "description": "Nueva lista de eventos / familias.",
                    "type": "array",
                    "items": {}
                  },
                  "description": {
                    "type": "string"
                  },
                  "status": {
                    "description": "`enabled` | `disabled`.",
                    "example": "enabled",
                    "type": "string"
                  },
                  "account_ids": {
                    "description": "Filtrar por números `acc_…`.",
                    "type": "array",
                    "items": {}
                  }
                },
                "required": [
                  "webhook_endpoint_id"
                ]
              },
              "example": {
                "status": "enabled",
                "events": [
                  "message.*",
                  "whatsapp.account.*",
                  "whatsapp.number.*"
                ]
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{webhook_endpoint_id}/rotate-secret": {
      "post": {
        "operationId": "webhooks-post-rotate-secret",
        "summary": "Rotar secreto",
        "description": "Genera un signing_secret nuevo. Durante expire_previous_in_seconds (default 24 h) cada entrega lleva dos firmas en X-Octuvia-Signature (v1=nuevo,v1=anterior) para migrar sin perder eventos.",
        "tags": [
          "Webhook Endpoints"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "webhook_endpoint",
                  "id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "url": "https://api.tuapp.com/octuvia/webhooks",
                  "events": [
                    "message.*",
                    "account.*"
                  ],
                  "status": "enabled",
                  "livemode": true,
                  "signing_secret": "whsec_nuevoSecretSoloAquí…",
                  "created_at": "2026-12-01T10:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "webhook_endpoint_id",
            "in": "path",
            "required": true,
            "description": "Id `we_…`.",
            "schema": {
              "type": "string",
              "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "webhook_endpoint_id": {
                    "description": "Id `we_…`.",
                    "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  },
                  "expire_previous_in_seconds": {
                    "description": "Ventana de doble firma. 0–604800. Default 86400.",
                    "example": 86400,
                    "type": "integer"
                  }
                },
                "required": [
                  "webhook_endpoint_id"
                ]
              },
              "example": {
                "expire_previous_in_seconds": 86400
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{webhook_endpoint_id}/test": {
      "post": {
        "operationId": "webhooks-post-test",
        "summary": "Probar endpoint",
        "description": "Envía un evento webhook.test firmado a tu URL y devuelve el resultado del intento (status HTTP y cuerpo). No reintenta.",
        "tags": [
          "Webhook Endpoints"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "webhook_delivery",
                  "id": "whd_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "event_id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "event_type": "webhook.test",
                  "webhook_endpoint_id": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "status": "delivered",
                  "attempts": 1,
                  "http_status": 200,
                  "created_at": "2026-12-03T08:10:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "webhook_endpoint_id",
            "in": "path",
            "required": true,
            "description": "Id `we_…`.",
            "schema": {
              "type": "string",
              "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "webhook_endpoint_id": {
                    "description": "Id `we_…`.",
                    "example": "we_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                    "type": "string"
                  }
                },
                "required": [
                  "webhook_endpoint_id"
                ]
              }
            }
          }
        }
      }
    },
    "/whatsapp/connect-link": {
      "post": {
        "operationId": "communications-whatsapp-connection-post-connect-links",
        "summary": "Crear connect link",
        "description": "Crea una URL alojada por Octuvia (con tu marca). El usuario completa el Embedded Signup de Meta, elige o registra el número, y el navegador vuelve a tu return_url.\n\nCanal en la ruta (`/whatsapp/…`). La API key (`octuvia_live_…`) identifica el workspace. Recomendado `Idempotency-Key`. `return_url` `https` con host en **Configuración → Dominios de return_url** (si no → 422 `RETURN_URL_NOT_ALLOWED`).",
        "tags": [
          "Whatsapp"
        ],
        "responses": {
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "connect_link",
                  "id": "cl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "url": "https://connect.octuvia.com/cl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "platform": "whatsapp",
                  "onboarding": "cloud_api",
                  "reference": "onboarding-demo",
                  "return_url": "https://dev-app.octuvia.com/channels/whatsapp",
                  "status": "pending",
                  "account_id": null,
                  "error_code": null,
                  "expires_at": "2026-03-27T12:00:00Z",
                  "completed_at": null,
                  "created_at": "2026-03-26T12:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          },
          "422": {
            "description": "return_url no permitido",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "RETURN_URL_NOT_ALLOWED",
                    "message": "El dominio de return_url no está en la lista de dominios permitidos del tenant.",
                    "param": "return_url",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "return_url": {
                    "description": "URL `https` a la que vuelve el navegador al terminar (o cancelar/fallar). Si omites, Octuvia usa la consola (`/channels/whatsapp`). El host debe estar en Configuración → Dominios de return_url.",
                    "example": "https://dev-app.octuvia.com/channels/whatsapp",
                    "type": "string"
                  },
                  "onboarding": {
                    "description": "Solo WhatsApp. `cloud_api` (default) = solo API. `business_app` = coexistencia con la app del móvil. Ver tabla más abajo.",
                    "example": "cloud_api",
                    "type": "string"
                  },
                  "reference": {
                    "description": "Id libre tuyo (ej. cliente CRM). Vuelve en el redirect, en el ConnectLink y en el evento `account.connected`. Máx. 200 caracteres.",
                    "example": "cliente-778",
                    "type": "string"
                  },
                  "account_id": {
                    "description": "Opcional. Si el número ya existe y está en `reauthorization_required`, pásalo para reconectar ese `acc_…` en lugar de crear otro.",
                    "type": "string"
                  },
                  "expires_in_seconds": {
                    "description": "TTL del enlace. Mín. 300, máx. 604800. Default 86400 (24 h).",
                    "example": 86400,
                    "type": "integer"
                  },
                  "locale": {
                    "description": "Idioma de la página alojada: `es` | `en` | `pt`. Default `es`.",
                    "example": "es",
                    "type": "string"
                  },
                  "branding": {
                    "description": "Apariencia de la página de conexión. Si omites, se usa la marca del panel.",
                    "type": "object",
                    "properties": {
                      "brand_name": {
                        "description": "Nombre mostrado en la página. Máx. 60.",
                        "example": "Agencia Nova",
                        "type": "string"
                      },
                      "logo_url": {
                        "description": "URL pública del logo.",
                        "type": "string"
                      },
                      "primary_color": {
                        "description": "Color hex `#RRGGBB`.",
                        "example": "#6D28D9",
                        "type": "string"
                      }
                    }
                  }
                }
              },
              "example": {
                "return_url": "https://dev-app.octuvia.com/channels/whatsapp",
                "onboarding": "cloud_api",
                "locale": "es",
                "reference": "onboarding-demo"
              }
            }
          }
        }
      }
    },
    "/whatsapp/connect-links/{connect_link_id}": {
      "get": {
        "operationId": "communications-whatsapp-connection-get-connect-links",
        "summary": "Estado del connect link",
        "description": "Consulta un enlace: `pending` → `completed` (con `account_id`) | `cancelled` | `failed` | `expired`. Úsalo para confirmar el alta tras el redirect.",
        "tags": [
          "Whatsapp"
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "connect_link",
                  "id": "cl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "url": "https://connect.octuvia.com/cl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "platform": "whatsapp",
                  "onboarding": "cloud_api",
                  "reference": "onboarding-demo",
                  "return_url": "https://dev-app.octuvia.com/channels/whatsapp",
                  "status": "completed",
                  "account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
                  "error_code": null,
                  "expires_at": "2026-03-27T12:00:00Z",
                  "completed_at": "2026-03-26T12:05:00Z",
                  "created_at": "2026-03-26T12:00:00Z"
                }
              }
            }
          },
          "401": {
            "description": "No autorizado"
          },
          "404": {
            "description": "Enlace no encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "CONNECT_LINK_NOT_FOUND",
                    "message": "No existe el enlace indicado.",
                    "param": "connect_link_id",
                    "request_id": "req_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "connect_link_id",
            "in": "path",
            "required": true,
            "description": "Id del enlace (`cl_…`) en la ruta.",
            "schema": {
              "type": "string",
              "example": "cl_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
            }
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Secret key de developer. En Postman/Insomnia/Bruno usa la variable bearerToken (ejemplo: octuvia_live_…). Producción: octuvia_live_…"
      }
    }
  },
  "x-collection-variables": [
    {
      "key": "baseUrl",
      "value": "https://api.octuvia.com/v1"
    },
    {
      "key": "bearerToken",
      "value": "octuvia_live_…"
    }
  ]
}