{
  "openapi": "3.1.0",
  "info": {
    "title": "API pública do Preflow",
    "version": "1.0.0",
    "summary": "Integre o sistema da sua empresa ao Preflow.",
    "description": "API REST para o sistema da sua empresa (ERP, app, e-commerce, CRM próprio)\nconversar com o Preflow. Guias em https://developers.preflow.sale/pt/.\n\n- Autenticação por chave secreta do workspace (`Authorization: Bearer pf_live_…`).\n- Todo POST, PATCH e DELETE exige `Idempotency-Key`.\n- Datas em ISO-8601 (UTC), telefones em E.164, ids em UUID.\n- Erros sempre no formato `{ \"error\": { code, message, request_id, retryable, details } }`.\n",
    "contact": {
      "name": "Preflow",
      "url": "https://preflow.sale"
    }
  },
  "servers": [
    {
      "url": "https://api.preflow.sale",
      "description": "Produção"
    },
    {
      "url": "https://api-hml.preflow.sale",
      "description": "Homologação"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Conta",
      "description": "A chave e o workspace dela."
    },
    {
      "name": "WhatsApp",
      "description": "Linhas, templates, janela de 24 h, envio, status, histórico e mídia."
    },
    {
      "name": "Arquivos",
      "description": "Upload de arquivos para mandar como mídia."
    },
    {
      "name": "Leads",
      "description": "Criar lead (entra como inbound), buscar e ler a linha do tempo."
    },
    {
      "name": "Conversões",
      "description": "Conversão inbound: uma pessoa pediu contato no seu site, app ou sistema.\nSegue o mesmo caminho de um formulário do Preflow (MQL, atribuição,\ncadência de Inbound). Guia em https://developers.preflow.sale/pt/guides/website-leads/.\n"
    },
    {
      "name": "Contas e funis",
      "description": "Etapa por funil, etapa intermediária, donos, qualificação e Cliente/Churn."
    },
    {
      "name": "Cadências",
      "description": "Listar cadências, inscrever um lead e parar a cadência dele."
    },
    {
      "name": "Reuniões",
      "description": "Reuniões marcadas (sem os espelhos de agenda)."
    },
    {
      "name": "Webhooks",
      "description": "Endpoints que recebem os avisos do Preflow, assinados no padrão Standard\nWebhooks. Guia em https://developers.preflow.sale/pt/guides/webhooks/.\n"
    },
    {
      "name": "Eventos",
      "description": "Catálogo de eventos e consulta de um evento já emitido."
    }
  ],
  "paths": {
    "/v1/me": {
      "get": {
        "tags": [
          "Conta"
        ],
        "operationId": "getMe",
        "summary": "Workspace, escopos e limites da chave",
        "description": "Qualquer chave válida pode chamar. Use para conferir a configuração da integração.",
        "responses": {
          "200": {
            "description": "Contexto da chave.",
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/openapi.json": {
      "get": {
        "tags": [
          "Conta"
        ],
        "operationId": "getOpenApi",
        "summary": "Esta especificação",
        "security": [],
        "responses": {
          "200": {
            "description": "Especificação OpenAPI 3.1 da API.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/whatsapp/senders": {
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "listWhatsAppSenders",
        "summary": "Linhas de WhatsApp do workspace",
        "description": "Números que a API pode usar em `from`: o de cada pessoa ativa do\nworkspace e o número próprio de cada agente de IA ativo. O WhatsApp\nBusiness do celular de uma pessoa é o telefone pessoal dela e fica fora da API.\n",
        "x-required-scope": "whatsapp:read",
        "responses": {
          "200": {
            "description": "Linhas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WhatsAppSender"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/v1/whatsapp/templates": {
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "listWhatsAppTemplates",
        "summary": "Templates de WhatsApp",
        "description": "Por padrão só os aprovados para o provedor do workspace.",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "approved",
                "all"
              ],
              "default": "approved"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Templates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WhatsAppTemplate"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/v1/whatsapp/window": {
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "getWhatsAppWindow",
        "summary": "Janela de 24 h com um contato",
        "description": "Aberta: dá para mandar texto e mídia. Fechada: só template aprovado.\nA janela é de cada linha: conta a última mensagem do contato para essa linha.\n",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "+5511999998888"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Id da linha. Sem ele, a linha padrão da chave.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Estado da janela.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WhatsAppWindow"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/v1/files": {
      "post": {
        "tags": [
          "Arquivos"
        ],
        "operationId": "createFile",
        "summary": "Preparar o upload de um arquivo",
        "description": "Devolve uma URL para enviar os bytes com `PUT` (válida por 2 h). Depois\nuse o `id` em `media.file_id` ao mandar a mensagem. Até 16 MB; o arquivo\nenviado tem que ter o tamanho e o tipo declarados. 60 por minuto e 1.000\npor dia por chave; o arquivo é apagado 30 dias depois.\n",
        "x-required-scope": "whatsapp:send",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "filename",
                  "content_type",
                  "size"
                ],
                "additionalProperties": false,
                "properties": {
                  "filename": {
                    "type": "string",
                    "maxLength": 200,
                    "example": "pedido-1234.pdf"
                  },
                  "content_type": {
                    "type": "string",
                    "example": "application/pdf"
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 16777216,
                    "description": "Tamanho em bytes."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Arquivo registrado e URL de upload.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "413": {
            "$ref": "#/components/responses/BadRequest"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/v1/whatsapp/messages": {
      "post": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "sendWhatsAppMessage",
        "summary": "Mandar WhatsApp",
        "description": "Manda texto, template aprovado ou mídia para um telefone ou um lead,\npor uma linha do workspace. Passa pelas mesmas regras de qualquer envio\ndo Preflow (privacidade, contato pausado ou encerrado, plano e créditos,\nqualidade da linha). Fora da janela de 24 h só template aprovado.\n\n- Número que ainda não é lead vira **contato** (não lead).\n- A mensagem não tira a conversa de quem conduz (IA ou pessoa) e não\n  conta nos painéis de toques.\n- Cobrança: a tabela de WhatsApp do Preflow; recusa do provedor devolve o crédito.\n- `202` com `status: unknown`: o resultado ficou incerto. Nada é\n  reenviado; consulte `GET /v1/whatsapp/messages/{id}`.\n",
        "x-required-scope": "whatsapp:send",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendWhatsAppMessage"
              },
              "examples": {
                "texto": {
                  "value": {
                    "to": "+5511999998888",
                    "text": "Seu pedido 1234 saiu para entrega.",
                    "client_reference": "pedido-1234"
                  }
                },
                "template": {
                  "value": {
                    "lead_id": "3f0c2a5e-8a4b-4b8e-9a5a-1f2d3c4b5a69",
                    "template": {
                      "name": "pedido_enviado",
                      "language": "pt_BR",
                      "variables": {
                        "nome": "Ana",
                        "pedido": "1234"
                      }
                    }
                  }
                },
                "midia": {
                  "value": {
                    "to": "+5511999998888",
                    "media": {
                      "file_id": "7d1e2c3b-4a5f-4e6d-8c7b-9a0f1e2d3c4b",
                      "caption": "Segue o boleto."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Enviada.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WhatsAppMessage"
                }
              }
            }
          },
          "202": {
            "description": "Resultado incerto; nada será reenviado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "id"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "unknown"
                    },
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "listWhatsAppMessages",
        "summary": "Histórico com um contato",
        "description": "Todas as mensagens com o telefone, de todas as origens, da mais nova para a mais antiga.",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "+5511999998888"
            }
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Página de mensagens.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WhatsAppHistoryMessage"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/v1/whatsapp/messages/{id}": {
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "getWhatsAppMessage",
        "summary": "Uma mensagem e o status de entrega",
        "description": "Aceita o `id` devolvido pelo envio (status `sending`, `sent`,\n`delivered`, `read`, `failed` ou `unknown`) ou o `id` de uma mensagem do histórico.\n",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Mensagem.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/WhatsAppMessage"
                    },
                    {
                      "$ref": "#/components/schemas/WhatsAppHistoryMessage"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/whatsapp/messages/{id}/media": {
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "getWhatsAppMessageMedia",
        "summary": "Baixar a mídia de uma mensagem",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Os bytes da mídia, com o Content-Type original.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/leads": {
      "post": {
        "tags": [
          "Leads"
        ],
        "operationId": "createLead",
        "summary": "Criar lead (entrada inbound)",
        "description": "O lead entra como **inbound** e segue a configuração de Inbound do\nworkspace (cadência, dono e aviso a quem atende). Informe `email` ou\n`phone` (ou os dois).\n\n- Já existe um lead com o mesmo e-mail ou telefone: devolve esse lead\n  (`200`, `created: false`) sem alterar nada nele. Lead já em\n  atendimento (em cadência, perdido, ganho ou de prospecção) nunca é\n  reaberto.\n- A foto do lead (`lead`) só vem para chave com `leads:read`; sem ela, a\n  resposta traz só `lead_id`.\n- Limite próprio: 60 leads por minuto por chave.\n- `external_id` é o id do lead no seu sistema, único no workspace:\n  enviar de novo o mesmo `external_id` devolve o mesmo lead, sem mudar\n  nada.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadCreate"
              },
              "example": {
                "name": "Ana Souza",
                "email": "ana@empresa.com.br",
                "phone": "+5511999998888",
                "company": "Empresa",
                "position": "Diretora comercial",
                "external_id": "erp-12345",
                "source": "erp"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O lead já existia (mesmo external_id, e-mail ou telefone).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadCreateResult"
                }
              }
            }
          },
          "201": {
            "description": "Lead criado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadCreateResult"
                }
              }
            }
          },
          "202": {
            "$ref": "#/components/responses/OutcomeUnknown"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "get": {
        "tags": [
          "Leads"
        ],
        "operationId": "listLeads",
        "summary": "Buscar e listar leads",
        "description": "Sem filtro, lista todos os leads em ordem de atualização (o mais antigo\nprimeiro). Use `updated_since` para sincronizar só o que mudou. Leads\nmesclados não aparecem.\n",
        "parameters": [
          {
            "name": "email",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "email"
            }
          },
          {
            "name": "phone",
            "in": "query",
            "description": "Telefone em E.164.",
            "schema": {
              "type": "string",
              "example": "+5511999998888"
            }
          },
          {
            "name": "external_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "description": "Só leads atualizados a partir desta data (ISO-8601).",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de leads.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/inbound-submissions": {
      "post": {
        "tags": [
          "Conversões"
        ],
        "operationId": "createInboundSubmission",
        "summary": "Registrar uma conversão inbound",
        "description": "Use quando uma **pessoa pediu contato** (formulário do seu site, landing,\napp, chat próprio). A conversão segue o caminho de um formulário do\nPreflow: vira MQL, conta na atribuição e começa a cadência de Inbound do\nworkspace. Para sincronizar cadastros do seu sistema, use `POST /v1/leads`.\n\n- **MQL por padrão.** Mande `\"qualified\": false` para registrar só como\n  contato (sem lead, dono nem cadência). Com `form_id`, as regras de MQL\n  daquele formulário do Preflow decidem.\n- **Lead que já existe** (mesmo e-mail, telefone ou LinkedIn): a conversão\n  entra no histórico dele e o MQL atualiza a conta. Lead perdido, ganho,\n  arquivado ou já em atendimento nunca é reaberto (`result: lead_unchanged`).\n- **`submission_id`** é o id da conversão no seu sistema, único no\n  workspace. Mandar de novo devolve a mesma conversão, com qualquer\n  `Idempotency-Key`; com outro conteúdo, `409 submission_id_conflict`.\n  Depois de um `202`, repita com o mesmo `submission_id`: a conversão é\n  retomada sem duplicar.\n- `campaign` (slug de uma campanha do Preflow) e `attribution.utm_campaign`\n  chegam às regras de roteamento de Inbound.\n- Limite próprio: 120 conversões por minuto por chave.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InboundSubmissionCreate"
              },
              "example": {
                "submission_id": "site-form-8812",
                "contact": {
                  "name": "Ana Souza",
                  "email": "ana@empresa.com.br",
                  "phone": "+5511999998888",
                  "company": "Empresa",
                  "position": "Diretora comercial"
                },
                "answers": [
                  {
                    "key": "tamanho_time",
                    "label": "Quantas pessoas no time comercial?",
                    "value": "11-50"
                  },
                  {
                    "key": "interesse",
                    "label": "O que você procura?",
                    "value": "Prospecção outbound"
                  }
                ],
                "campaign": "black-friday-2026",
                "attribution": {
                  "utm_source": "google",
                  "utm_medium": "cpc",
                  "utm_campaign": "black-friday-2026",
                  "gclid": "Cj0KCQiA",
                  "landing_url": "https://empresa.com.br/contato"
                },
                "consent": {
                  "granted": true,
                  "text": "Aceito receber contato da Empresa."
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Conversão registrada num lead que já existia, só como contato, ou a\nmesma conversão (`submission_id`) já registrada antes.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundSubmission"
                }
              }
            }
          },
          "201": {
            "description": "Conversão registrada e lead criado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundSubmission"
                }
              }
            }
          },
          "202": {
            "$ref": "#/components/responses/OutcomeUnknown"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/inbound-submissions/{id}": {
      "get": {
        "tags": [
          "Conversões"
        ],
        "operationId": "getInboundSubmission",
        "summary": "Ler uma conversão",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "A conversão.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundSubmission"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/leads/{id}": {
      "get": {
        "tags": [
          "Leads"
        ],
        "operationId": "getLead",
        "summary": "Ler um lead",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "O lead.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Lead"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/leads/{id}/activities": {
      "get": {
        "tags": [
          "Leads"
        ],
        "operationId": "listLeadActivities",
        "summary": "Linha do tempo do lead",
        "description": "Do mais recente para o mais antigo. Só tipos públicos (lista em\n`ActivityType`); registros internos não aparecem.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de atividades.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ActivityPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/leads/{id}/cadence-enrollments": {
      "post": {
        "tags": [
          "Cadências"
        ],
        "operationId": "enrollLeadInCadence",
        "summary": "Inscrever o lead numa cadência",
        "description": "Mesma inscrição da tela, com as mesmas recusas (lead já em cadência,\npausa de engajamento, lead que passou por reunião, cooldown de\nperdido, cadência que nasceria toda cancelada). Quem executa as etapas\né o dono de pré-vendas da conta do lead. Limite próprio: 60 inscrições\npor minuto por chave.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "cadence_id"
                ],
                "properties": {
                  "cadence_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Id de GET /v1/cadences."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lead inscrito.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CadenceEnrollment"
                }
              }
            }
          },
          "202": {
            "$ref": "#/components/responses/OutcomeUnknown"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/leads/{id}/cadence-stop": {
      "post": {
        "tags": [
          "Cadências"
        ],
        "operationId": "stopLeadCadence",
        "summary": "Parar a cadência do lead",
        "description": "Cancela as etapas de cadência ainda abertas **deste lead**. As outras\npessoas da mesma conta continuam nas cadências delas; conversa em\nandamento e follow-up marcado à mão também continuam. O que estava na\nfila de envio é cancelado; o que o provedor já recebeu não volta. Sem\ncadência aberta, responde `stopped: false`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resultado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CadenceStop"
                }
              }
            }
          },
          "202": {
            "$ref": "#/components/responses/OutcomeUnknown"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/cadences": {
      "get": {
        "tags": [
          "Cadências"
        ],
        "operationId": "listCadences",
        "summary": "Cadências do workspace",
        "description": "Cadências que podem receber leads (sem as arquivadas e sem as de sistema).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de cadências.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CadencePage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/accounts": {
      "get": {
        "tags": [
          "Contas e funis"
        ],
        "operationId": "listAccounts",
        "summary": "Listar contas",
        "description": "Em ordem de atualização (a mais antiga primeiro). Use `updated_since` para sincronizar só o que mudou.",
        "parameters": [
          {
            "name": "updated_since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de contas.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/accounts/{id}": {
      "get": {
        "tags": [
          "Contas e funis"
        ],
        "operationId": "getAccount",
        "summary": "Ler uma conta",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "A conta.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/funnels": {
      "get": {
        "tags": [
          "Contas e funis"
        ],
        "operationId": "listFunnels",
        "summary": "Funis e etapas",
        "responses": {
          "200": {
            "description": "Todos os funis do workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Funnel"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/meetings": {
      "get": {
        "tags": [
          "Reuniões"
        ],
        "operationId": "listMeetings",
        "summary": "Listar reuniões",
        "description": "Em ordem de data da reunião. Bloqueios copiados da agenda do Outlook ou\ndo Google não são reuniões e nunca aparecem.\n",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "Reuniões a partir desta data.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Reuniões antes desta data.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "lead_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/MeetingStatus"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de reuniões.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MeetingPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/meetings/{id}": {
      "get": {
        "tags": [
          "Reuniões"
        ],
        "operationId": "getMeeting",
        "summary": "Ler uma reunião",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "A reunião.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meeting"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/event-types": {
      "get": {
        "tags": [
          "Eventos"
        ],
        "operationId": "listEventTypes",
        "summary": "Tipos de evento que um endpoint pode assinar",
        "responses": {
          "200": {
            "description": "Catálogo de eventos disponíveis.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEventType"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/events/{id}": {
      "get": {
        "tags": [
          "Eventos"
        ],
        "operationId": "getEvent",
        "summary": "Um evento emitido nos últimos 30 dias, com as entregas",
        "description": "O evento leva o recurso: além de `webhooks:manage`, a chave precisa do\nacesso de leitura do módulo do tipo (`whatsapp:read`, `leads:read`,\n`accounts:read` ou `meetings:read`); sem ele, `403 insufficient_scope`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EventId"
          }
        ],
        "responses": {
          "200": {
            "description": "O evento (mesmo envelope que o webhook leva) e as entregas dele.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEventWithDeliveries"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhook-endpoints": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhookEndpoints",
        "summary": "Endpoints do workspace",
        "responses": {
          "200": {
            "description": "Até 10 endpoints, sem o segredo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor",
                    "max_endpoints"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEndpoint"
                      }
                    },
                    "next_cursor": {
                      "type": "null"
                    },
                    "max_endpoints": {
                      "type": "integer",
                      "example": 10
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "createWebhookEndpoint",
        "summary": "Cadastra um endpoint",
        "description": "A resposta traz o segredo `whsec_…` **uma vez só**. Guarde no cofre de\nsegredos do servidor que recebe os webhooks. Até 10 endpoints por workspace\ne 30 cadastros por hora (depois, `429`).\n\nCada evento leva o recurso (texto da mensagem, telefone, lead): a chave\nprecisa também do acesso de leitura do módulo de cada tipo assinado\n(`whatsapp.*` → `whatsapp:read`, `lead.*` → `leads:read`, `account.*` →\n`accounts:read`, `meeting.*` → `meetings:read`); sem ele,\n`403 insufficient_scope` com `details.required_scope`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEndpointCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Endpoint criado, com o segredo.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhook-endpoints/{id}": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "getWebhookEndpoint",
        "summary": "Um endpoint",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          }
        ],
        "responses": {
          "200": {
            "description": "O endpoint, sem o segredo.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "patch": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "updateWebhookEndpoint",
        "summary": "Edita, desliga ou religa um endpoint",
        "description": "Campo ausente não muda. `status: \"disabled\"` para as entregas na hora e\ncancela as pendentes; `status: \"active\"` religa e zera a contagem de falhas.\nMudar `url` ou `events`, ou religar, exige o acesso de leitura de todos os\ntipos que o endpoint passa a receber (veja o cadastro).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEndpointUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O endpoint atualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "deleteWebhookEndpoint",
        "summary": "Exclui um endpoint",
        "description": "O segredo e o log de entregas do endpoint são apagados.",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Endpoint excluído.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "deleted"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "deleted": {
                      "type": "boolean",
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhook-endpoints/{id}/rotate-secret": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "rotateWebhookSecret",
        "summary": "Gera um segredo novo",
        "description": "O segredo anterior continua assinando por 24 h: nesse período o cabeçalho\n`webhook-signature` leva as duas assinaturas, e o seu receptor pode trocar\no segredo sem perder evento. Uma nova rotação nessas 24 h responde\n`409 webhook_rotation_in_progress`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O segredo novo (aparece uma vez só).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "secret",
                    "previous_secret_expires_at"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "secret": {
                      "description": "`null` (com `secret_redacted: true`) na repetição com a mesma `Idempotency-Key`.",
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/WebhookSecret"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "secret_redacted": {
                      "type": "boolean"
                    },
                    "previous_secret_expires_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhook-endpoints/{id}/test": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "testWebhookEndpoint",
        "summary": "Manda um evento de teste",
        "description": "Cria um evento `webhook.test` só para este endpoint e o entrega pelo\ncaminho normal (assinado, com novas tentativas). Acompanhe pela lista de\nentregas. Até 5 testes por minuto por endpoint (depois, `429`).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "202": {
            "description": "Evento de teste na fila.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "event",
                    "delivery"
                  ],
                  "properties": {
                    "event": {
                      "$ref": "#/components/schemas/WebhookEvent"
                    },
                    "delivery": {
                      "$ref": "#/components/schemas/WebhookDelivery"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhook-endpoints/{id}/deliveries": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhookDeliveries",
        "summary": "Log de entregas do endpoint (30 dias)",
        "description": "Mais recentes primeiro. Guarda status, código HTTP e tempo de cada tentativa, nunca o corpo da resposta.",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/WebhookDeliveryStatus"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de entregas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhook-deliveries/{id}/retry": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "retryWebhookDelivery",
        "summary": "Reenvia uma entrega agora",
        "description": "Vale para entrega pendente, que falhou ou foi cancelada; entrega que já\ndeu certo é recusada (`409 webhook_delivery_already_succeeded`). O\nendpoint precisa estar ativo. Até 10 reenvios por minuto por endpoint\n(depois, `429 rate_limited`, `details.bucket: webhook_retry`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "202": {
            "description": "Entrega na fila para agora.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pf_live_<32 caracteres>",
        "description": "Chave secreta criada em Configurações → Integrações → API e webhooks.\nAparece uma vez só, na criação. Guarde no cofre de segredos do seu\nservidor e nunca use no navegador ou no app do celular.\n"
      }
    },
    "headers": {
      "X-Request-Id": {
        "description": "Identificador do pedido. Informe ao suporte.",
        "schema": {
          "type": "string",
          "example": "req_6f1c2b0e8a7d4c3b9e2f1a0d5c4b3a29"
        }
      },
      "RateLimit-Limit": {
        "description": "Pedidos permitidos na janela.",
        "schema": {
          "type": "integer",
          "example": 600
        }
      },
      "RateLimit-Remaining": {
        "description": "Pedidos que ainda cabem na janela.",
        "schema": {
          "type": "integer",
          "example": 599
        }
      },
      "RateLimit-Reset": {
        "description": "Segundos até a janela recomeçar.",
        "schema": {
          "type": "integer",
          "example": 42
        }
      },
      "Retry-After": {
        "description": "Segundos para tentar de novo.",
        "schema": {
          "type": "integer",
          "example": 42
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "Valor único por operação (ex.: um UUID). Repetir o mesmo pedido com a\nmesma chave em até 24 h devolve a mesma resposta sem executar de novo.\n",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "description": "Itens por página (1 a 100).",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "description": "Valor de `next_cursor` da página anterior.",
        "schema": {
          "type": "string"
        }
      },
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "EndpointId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Id do endpoint.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "EventId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Id do evento (`evt_…`), o mesmo do cabeçalho `webhook-id`.",
        "schema": {
          "type": "string",
          "pattern": "^evt_[0-9a-f]{32}$"
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id",
              "retryable"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Código estável. Catálogo em https://developers.preflow.sale/pt/concepts/errors/.",
                "example": "insufficient_scope"
              },
              "message": {
                "type": "string",
                "example": "A chave não tem o escopo necessário para esta rota."
              },
              "request_id": {
                "type": "string",
                "example": "req_6f1c2b0e8a7d4c3b9e2f1a0d5c4b3a29"
              },
              "retryable": {
                "type": "boolean",
                "description": "true quando o mesmo pedido pode dar certo depois."
              },
              "details": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      },
      "Scope": {
        "type": "string",
        "enum": [
          "whatsapp:read",
          "whatsapp:send",
          "leads:read",
          "leads:write",
          "accounts:read",
          "meetings:read",
          "cadences:read",
          "cadences:write",
          "webhooks:manage"
        ]
      },
      "Me": {
        "type": "object",
        "required": [
          "api_version",
          "workspace",
          "api_key",
          "limits"
        ],
        "properties": {
          "api_version": {
            "type": "string",
            "const": "v1"
          },
          "workspace": {
            "type": "object",
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "api_key": {
            "type": "object",
            "required": [
              "id",
              "name",
              "environment",
              "scopes"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "environment": {
                "type": "string",
                "enum": [
                  "live",
                  "test"
                ]
              },
              "scopes": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Scope"
                }
              }
            }
          },
          "limits": {
            "type": "object",
            "required": [
              "requests_per_minute"
            ],
            "properties": {
              "requests_per_minute": {
                "type": "integer",
                "example": 600
              }
            }
          }
        }
      },
      "WhatsAppSender": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "phone",
          "owner",
          "is_default",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Use em `from`."
          },
          "kind": {
            "type": "string",
            "enum": [
              "person",
              "ai_agent"
            ]
          },
          "phone": {
            "type": "string",
            "example": "+5511988887777"
          },
          "owner": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "is_default": {
            "type": "boolean",
            "description": "Linha padrão da pessoa."
          },
          "status": {
            "type": "string",
            "enum": [
              "online",
              "offline",
              "unknown"
            ]
          }
        }
      },
      "WhatsAppTemplate": {
        "type": "object",
        "required": [
          "id",
          "name",
          "language",
          "status",
          "variables"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "description": "Use em `template.name`."
          },
          "display_name": {
            "type": "string"
          },
          "language": {
            "type": "string",
            "example": "pt_BR"
          },
          "category": {
            "type": [
              "string",
              "null"
            ],
            "example": "utility"
          },
          "status": {
            "type": "string",
            "example": "approved"
          },
          "body": {
            "type": [
              "string",
              "null"
            ],
            "example": "Oi {{nome}}, seu pedido {{pedido}} saiu para entrega."
          },
          "variables": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Preencha todas em `template.variables`, pelo nome ou pela posição (`\"1\"`, `\"2\"`…)."
          },
          "header": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "type": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "WhatsAppWindow": {
        "type": "object",
        "required": [
          "to",
          "from",
          "open",
          "last_inbound_at",
          "expires_at"
        ],
        "properties": {
          "to": {
            "type": "string"
          },
          "from": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "phone": {
                "type": "string"
              }
            }
          },
          "open": {
            "type": "boolean"
          },
          "last_inbound_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "File": {
        "type": "object",
        "required": [
          "id",
          "filename",
          "content_type",
          "size",
          "upload"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string"
          },
          "size": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "upload_expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "upload": {
            "type": "object",
            "required": [
              "method",
              "url",
              "headers",
              "expires_at"
            ],
            "properties": {
              "method": {
                "type": "string",
                "const": "PUT"
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "headers": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "expires_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "SendWhatsAppMessage": {
        "type": "object",
        "additionalProperties": false,
        "description": "Informe `to` ou `lead_id` (com os dois, `to` tem que ser telefone do\nlead), e exatamente um entre `text`, `template` e `media`.\n",
        "properties": {
          "to": {
            "type": "string",
            "description": "Telefone em E.164.",
            "example": "+5511999998888"
          },
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "from": {
            "type": "string",
            "format": "uuid",
            "description": "Id da linha. Sem ele, a linha padrão da chave."
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096
          },
          "template": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "language": {
                "type": "string",
                "example": "pt_BR"
              },
              "variables": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              }
            }
          },
          "media": {
            "type": "object",
            "required": [
              "file_id"
            ],
            "properties": {
              "file_id": {
                "type": "string",
                "format": "uuid"
              },
              "caption": {
                "type": "string",
                "maxLength": 1024
              }
            }
          },
          "contact_name": {
            "type": "string",
            "maxLength": 120,
            "description": "Nome do contato criado quando o número não é lead."
          },
          "client_reference": {
            "type": "string",
            "maxLength": 200,
            "description": "Seu id; volta no status e nos webhooks."
          }
        }
      },
      "WhatsAppMessage": {
        "type": "object",
        "required": [
          "id",
          "to",
          "from",
          "type",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "to": {
            "type": "string"
          },
          "from": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "kind": {
                "type": "string",
                "enum": [
                  "person",
                  "ai_agent"
                ]
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "lead_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "contact_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "conversation_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "template",
              "media"
            ]
          },
          "template": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "language": {
                "type": "string"
              }
            }
          },
          "client_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "sending",
              "sent",
              "delivered",
              "read",
              "failed",
              "unknown"
            ]
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "code": {
                "type": "string"
              }
            }
          },
          "message_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Id da mensagem no histórico."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WhatsAppHistoryMessage": {
        "type": "object",
        "required": [
          "id",
          "direction",
          "type",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "direction": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "template",
              "media"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "media": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "type": {
                "type": "string",
                "example": "image"
              }
            }
          },
          "template": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "name": {
                "type": "string"
              }
            }
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "from": {
            "type": [
              "string",
              "null"
            ]
          },
          "to": {
            "type": [
              "string",
              "null"
            ]
          },
          "conversation_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "origin": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "api",
              "cadence",
              "ai",
              "human",
              "whatsapp_app",
              null
            ],
            "description": "Quem mandou (só nas enviadas)."
          },
          "api_message_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "client_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Timestamp": {
        "type": [
          "string",
          "null"
        ],
        "format": "date-time",
        "example": "2026-11-16T12:34:56.789Z"
      },
      "ProfileRef": {
        "type": [
          "object",
          "null"
        ],
        "required": [
          "id",
          "name",
          "is_ai_agent"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "is_ai_agent": {
            "type": "boolean"
          }
        }
      },
      "InboundSubmissionCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "contact"
        ],
        "properties": {
          "contact": {
            "type": "object",
            "additionalProperties": false,
            "description": "Informe `email` ou `phone`.",
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 200
              },
              "email": {
                "type": "string",
                "format": "email",
                "maxLength": 320
              },
              "phone": {
                "type": "string",
                "description": "E.164.",
                "example": "+5511999998888",
                "pattern": "^\\+[1-9][0-9]{7,14}$"
              },
              "company": {
                "type": "string",
                "maxLength": 200
              },
              "position": {
                "type": "string",
                "maxLength": 120
              },
              "linkedin_url": {
                "type": "string",
                "maxLength": 500,
                "example": "https://www.linkedin.com/in/ana-souza"
              }
            }
          },
          "submission_id": {
            "type": "string",
            "maxLength": 128,
            "description": "Id da conversão no seu sistema, único no workspace (ASCII visível, sem espaço)."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "Quando a pessoa converteu. Padrão, agora. Até 30 dias no passado."
          },
          "answers": {
            "type": "array",
            "maxItems": 40,
            "description": "Respostas do formulário, guardadas na conversão e no lead novo. Com\n`form_id`, `key` é o id do campo no formulário do Preflow e as regras\nde MQL dele valem. Até 64 KB somadas; texto com caractere de controle\n(fora tab e quebra de linha) é recusado com `400`.\n",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "key",
                "value"
              ],
              "properties": {
                "key": {
                  "type": "string",
                  "pattern": "^[A-Za-z0-9_.-]{1,64}$"
                },
                "label": {
                  "type": "string",
                  "maxLength": 200
                },
                "value": {
                  "oneOf": [
                    {
                      "type": "string",
                      "maxLength": 5000
                    },
                    {
                      "type": "number"
                    },
                    {
                      "type": "boolean"
                    },
                    {
                      "type": "array",
                      "maxItems": 30,
                      "items": {
                        "type": "string",
                        "maxLength": 500
                      }
                    }
                  ]
                }
              }
            }
          },
          "qualified": {
            "type": "boolean",
            "default": true,
            "description": "false registra só como contato. Ignorado quando o formulário de `form_id` tem regras de MQL."
          },
          "form_id": {
            "type": "string",
            "format": "uuid",
            "description": "Formulário publicado do Preflow cujas regras, funil e campanha valem."
          },
          "funnel_id": {
            "type": "string",
            "format": "uuid",
            "description": "Funil do lead. Padrão, o do formulário ou a configuração de Inbound."
          },
          "campaign": {
            "type": "string",
            "maxLength": 100,
            "description": "Slug de uma campanha do Preflow."
          },
          "source": {
            "type": "string",
            "maxLength": 80,
            "description": "Rótulo livre do seu sistema (ex. site), guardado na conversão."
          },
          "notes": {
            "type": "string",
            "maxLength": 2000
          },
          "attribution": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "utm_source": {
                "type": "string",
                "maxLength": 500
              },
              "utm_medium": {
                "type": "string",
                "maxLength": 500
              },
              "utm_campaign": {
                "type": "string",
                "maxLength": 500
              },
              "utm_term": {
                "type": "string",
                "maxLength": 500
              },
              "utm_content": {
                "type": "string",
                "maxLength": 500
              },
              "gclid": {
                "type": "string",
                "maxLength": 500
              },
              "fbclid": {
                "type": "string",
                "maxLength": 500
              },
              "fbc": {
                "type": "string",
                "maxLength": 500,
                "description": "Cookie _fbc da Meta. Com fbclid, fbc ou fbp a conversão vai para a API de Conversões da Meta quando ela está conectada."
              },
              "fbp": {
                "type": "string",
                "maxLength": 500,
                "description": "Cookie _fbp da Meta."
              },
              "li_fat_id": {
                "type": "string",
                "maxLength": 500
              },
              "landing_url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2000
              },
              "referrer_url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2000
              }
            }
          },
          "consent": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "granted"
            ],
            "properties": {
              "granted": {
                "type": "boolean"
              },
              "text": {
                "type": "string",
                "maxLength": 1000,
                "description": "Texto que a pessoa aceitou."
              },
              "granted_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "InboundSubmission": {
        "type": "object",
        "required": [
          "id",
          "object",
          "submission_id",
          "status",
          "result",
          "lead_id",
          "contact_id",
          "qualified",
          "mql_applied",
          "matched_by",
          "inbound_cadence",
          "form_id",
          "occurred_at",
          "created_at",
          "completed_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "inbound_submission"
          },
          "submission_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "completed",
              "processing",
              "failed"
            ]
          },
          "result": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "lead_created",
              "lead_updated",
              "lead_unchanged",
              "contact_only",
              null
            ],
            "description": "`lead_created` lead novo; `lead_updated` lead que já existia ganhou os\ndados que faltavam; `lead_unchanged` lead perdido, ganho, arquivado ou já\nem atendimento, só registrado; `contact_only` não MQL, só contato.\n"
          },
          "lead_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "contact_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "qualified": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "mql_applied": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "O MQL foi gravado agora (false quando o lead já estava acima ou uma pessoa decidiu outra coisa)."
          },
          "matched_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "Como o lead existente foi achado. Só para chave com `leads:read`."
          },
          "inbound_cadence": {
            "type": [
              "object",
              "null"
            ],
            "description": "O que a configuração de Inbound fez. null quando nada começou.",
            "required": [
              "started",
              "reason",
              "cadence_id"
            ],
            "properties": {
              "started": {
                "type": "boolean"
              },
              "reason": {
                "type": "string",
                "example": "distribution"
              },
              "cadence_id": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              }
            }
          },
          "form_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "O formulário de `form_id`, quando enviado."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lead": {
            "$ref": "#/components/schemas/Lead",
            "description": "Só para chave com `leads:read`."
          }
        }
      },
      "LeadCreate": {
        "type": "object",
        "additionalProperties": false,
        "description": "Informe `email` ou `phone`.",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 320
          },
          "phone": {
            "type": "string",
            "description": "E.164.",
            "example": "+5511999998888",
            "pattern": "^\\+[1-9][0-9]{7,14}$"
          },
          "company": {
            "type": "string",
            "maxLength": 200
          },
          "position": {
            "type": "string",
            "maxLength": 120
          },
          "external_id": {
            "type": "string",
            "maxLength": 128,
            "description": "Id do lead no seu sistema. Único no workspace."
          },
          "source": {
            "type": "string",
            "maxLength": 80,
            "description": "Rótulo livre do seu sistema (ex. erp), guardado na entrada."
          }
        }
      },
      "LeadCreateResult": {
        "type": "object",
        "required": [
          "lead_id",
          "created",
          "matched_by",
          "inbound_cadence"
        ],
        "properties": {
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "lead": {
            "$ref": "#/components/schemas/Lead",
            "description": "Só para chave com `leads:read`."
          },
          "created": {
            "type": "boolean"
          },
          "matched_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "Como o lead existente foi achado (external_id, email, telefone...). Só para chave com `leads:read`."
          },
          "inbound_cadence": {
            "type": [
              "object",
              "null"
            ],
            "description": "O que a configuração de Inbound fez. null quando o lead já estava em atendimento.",
            "required": [
              "started",
              "reason",
              "cadence_id"
            ],
            "properties": {
              "started": {
                "type": "boolean"
              },
              "reason": {
                "type": "string",
                "example": "distribution"
              },
              "cadence_id": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              }
            }
          }
        }
      },
      "Lead": {
        "type": "object",
        "required": [
          "id",
          "object",
          "name",
          "status",
          "origin",
          "external_ids",
          "cadence",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "lead"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "description": "E.164 quando o Preflow já normalizou."
          },
          "additional_phones": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "company": {
            "type": [
              "string",
              "null"
            ]
          },
          "position": {
            "type": [
              "string",
              "null"
            ]
          },
          "linkedin_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "description": "Ciclo do contato.",
            "enum": [
              "active",
              "new",
              "working",
              "contacted",
              "no_show",
              "nurture",
              "lost",
              "converted",
              "merged",
              "do_not_contact"
            ]
          },
          "qualification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "new",
              "in_progress",
              "mql",
              "sql",
              "disqualified",
              "customer",
              "churn",
              null
            ]
          },
          "origin": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "inbound",
              "outbound",
              null
            ],
            "description": "Como o lead entrou pela primeira vez (não muda)."
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "description": "Canal de aquisição."
          },
          "loss_reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Só com status lost."
          },
          "account_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "funnel_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "product_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "external_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "cadence": {
            "type": "object",
            "required": [
              "active",
              "cadence_ids"
            ],
            "properties": {
              "active": {
                "type": "boolean"
              },
              "cadence_ids": {
                "type": "array",
                "items": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "archived_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "updated_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "LeadPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Lead"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ActivityType": {
        "type": "string",
        "enum": [
          "email.sent",
          "email.received",
          "whatsapp.sent",
          "whatsapp.received",
          "call.made",
          "call.received",
          "linkedin.invitation_sent",
          "linkedin.invitation_accepted",
          "linkedin.sent",
          "linkedin.received",
          "meeting.scheduled",
          "meeting.confirmed",
          "meeting.completed",
          "lead.lost",
          "lead.reactivated",
          "lead.status_changed",
          "lead.received_from_api",
          "note"
        ]
      },
      "Activity": {
        "type": "object",
        "required": [
          "id",
          "object",
          "lead_id",
          "type",
          "actor",
          "occurred_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "activity"
          },
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "$ref": "#/components/schemas/ActivityType"
          },
          "channel": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "email",
              "whatsapp",
              "call",
              "linkedin",
              "meeting",
              null
            ]
          },
          "direction": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "inbound",
              "outbound",
              null
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 1000
          },
          "actor": {
            "type": "object",
            "required": [
              "type",
              "profile"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "human",
                  "ai",
                  "lead",
                  "integration",
                  "system"
                ]
              },
              "profile": {
                "$ref": "#/components/schemas/ProfileRef"
              }
            }
          },
          "call": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "connection_status": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "occurred_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "ActivityPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Activity"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "FunnelStageKey": {
        "type": "string",
        "description": "Etapa fixa do funil.",
        "enum": [
          "new",
          "qualified",
          "scheduled",
          "completed",
          "no_show",
          "negotiation",
          "won",
          "lost"
        ]
      },
      "Account": {
        "type": "object",
        "required": [
          "id",
          "object",
          "name",
          "qualification",
          "is_customer",
          "is_churn",
          "owners",
          "funnels",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "account"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "company",
              "person",
              null
            ]
          },
          "domain": {
            "type": [
              "string",
              "null"
            ]
          },
          "qualification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "new",
              "in_progress",
              "mql",
              "sql",
              "disqualified",
              "customer",
              "partner",
              "churn",
              null
            ]
          },
          "is_customer": {
            "type": "boolean",
            "description": "Conta marcada como Cliente."
          },
          "is_churn": {
            "type": "boolean",
            "description": "Conta marcada como Churn."
          },
          "owners": {
            "type": "object",
            "required": [
              "pre_sales",
              "sales"
            ],
            "properties": {
              "pre_sales": {
                "$ref": "#/components/schemas/ProfileRef"
              },
              "sales": {
                "$ref": "#/components/schemas/ProfileRef"
              }
            }
          },
          "funnels": {
            "type": "array",
            "description": "Uma entrada por funil em que a conta está.",
            "items": {
              "type": "object",
              "required": [
                "funnel_id",
                "stage",
                "on_board"
              ],
              "properties": {
                "funnel_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "funnel_name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "product_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "stage": {
                  "$ref": "#/components/schemas/FunnelStageKey"
                },
                "intermediate_stage": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                },
                "on_board": {
                  "type": "boolean",
                  "description": "false quando a conta saiu do quadro (Churn sai de todas as colunas; Cliente só fica em Vendas)."
                },
                "stage_entered_at": {
                  "$ref": "#/components/schemas/Timestamp"
                },
                "updated_at": {
                  "$ref": "#/components/schemas/Timestamp"
                }
              }
            }
          },
          "archived_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "updated_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "AccountPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Account"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Funnel": {
        "type": "object",
        "required": [
          "id",
          "object",
          "name",
          "is_active",
          "stages",
          "intermediate_stages"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "funnel"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "color": {
            "type": [
              "string",
              "null"
            ]
          },
          "is_active": {
            "type": "boolean"
          },
          "funnel_types": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "inbound",
                "outbound"
              ]
            }
          },
          "stages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "name"
              ],
              "properties": {
                "key": {
                  "$ref": "#/components/schemas/FunnelStageKey"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          },
          "intermediate_stages": {
            "type": "array",
            "description": "Etapas criadas pelo workspace dentro de uma etapa fixa.",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "stage",
                "position"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string"
                },
                "stage": {
                  "$ref": "#/components/schemas/FunnelStageKey"
                },
                "position": {
                  "type": "integer"
                }
              }
            }
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "updated_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "Cadence": {
        "type": "object",
        "required": [
          "id",
          "object",
          "name",
          "funnel_type",
          "steps_count",
          "channels"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "cadence"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "funnel_type": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ]
          },
          "steps_count": {
            "type": "integer"
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "updated_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "CadencePage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Cadence"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "CadenceEnrollment": {
        "type": "object",
        "required": [
          "lead_id",
          "cadence_id",
          "tasks_created"
        ],
        "properties": {
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "cadence_id": {
            "type": "string",
            "format": "uuid"
          },
          "tasks_created": {
            "type": "integer",
            "description": "Etapas criadas e abertas."
          },
          "born_cancelled_tasks": {
            "type": "integer",
            "description": "Etapas que nasceram canceladas (ex. canal sem contato)."
          },
          "operator_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Quem executa as etapas."
          },
          "skipped_channels": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "channel": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "CadenceStop": {
        "type": "object",
        "required": [
          "lead_id",
          "stopped",
          "cancelled_tasks",
          "cadence_ids"
        ],
        "properties": {
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "stopped": {
            "type": "boolean"
          },
          "cancelled_tasks": {
            "type": "integer"
          },
          "cadence_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "MeetingStatus": {
        "type": "string",
        "enum": [
          "scheduled",
          "confirmed",
          "tentative",
          "rescheduled",
          "completed",
          "no_show",
          "cancelled"
        ]
      },
      "Meeting": {
        "type": "object",
        "required": [
          "id",
          "object",
          "status",
          "starts_at",
          "ends_at",
          "duration_minutes"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "meeting"
          },
          "lead_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "account_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "funnel_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/MeetingStatus"
          },
          "starts_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "ends_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "duration_minutes": {
            "type": "integer"
          },
          "meeting_link": {
            "type": [
              "string",
              "null"
            ]
          },
          "location_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "category": {
            "type": [
              "string",
              "null"
            ],
            "description": "prospecting, negotiation, continuity, cs ou other."
          },
          "contact": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "company": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "closer": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "scheduled_by": {
            "$ref": "#/components/schemas/ProfileRef"
          },
          "booked_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "updated_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "MeetingPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Meeting"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "OutcomeUnknown": {
        "type": "object",
        "required": [
          "status",
          "request_id"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "unknown"
          },
          "request_id": {
            "type": "string"
          },
          "resource_type": {
            "type": "string"
          },
          "resource_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "WebhookSecret": {
        "type": "string",
        "pattern": "^whsec_[A-Za-z0-9+/]+={0,2}$",
        "description": "Segredo de assinatura. Aparece só na criação e na rotação.",
        "example": "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSwfQmfVNQhnkZ="
      },
      "WebhookEventTypeName": {
        "type": "string",
        "enum": [
          "whatsapp.message.received",
          "whatsapp.message.sent",
          "whatsapp.message.status_updated",
          "whatsapp.template.status_updated",
          "lead.created",
          "inbound.submission_received",
          "lead.lost",
          "account.stage_changed",
          "account.qualification_changed",
          "meeting.scheduled",
          "meeting.rescheduled",
          "meeting.cancelled",
          "meeting.completed",
          "meeting.no_show"
        ]
      },
      "WebhookEventType": {
        "type": "object",
        "required": [
          "type",
          "module",
          "description"
        ],
        "properties": {
          "type": {
            "$ref": "#/components/schemas/WebhookEventTypeName"
          },
          "module": {
            "type": "string",
            "example": "whatsapp"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "WebhookEndpointCreate": {
        "type": "object",
        "required": [
          "url",
          "events"
        ],
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "`https://`, sem usuário e senha. Endereço interno, privado ou do Preflow é recusado.",
            "example": "https://erp.suaempresa.com.br/webhooks/preflow"
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/WebhookEventTypeName"
            }
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          }
        }
      },
      "WebhookEndpointUpdate": {
        "type": "object",
        "additionalProperties": false,
        "minProperties": 1,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/WebhookEventTypeName"
            }
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "disabled"
            ]
          }
        }
      },
      "WebhookEndpoint": {
        "type": "object",
        "required": [
          "id",
          "url",
          "status",
          "events",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "disabled",
              "paused_plan"
            ],
            "description": "`paused_plan`: o plano do workspace não tem API; as entregas ficam guardadas e saem quando o plano volta."
          },
          "disabled_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "manual",
              "failing",
              "creator_lost_access",
              null
            ],
            "description": "`failing`: falhou por 3 dias seguidos. `creator_lost_access`: quem criou (a pessoa ou a chave) não\nadministra mais o workspace. Nos dois casos os administradores são avisados; religar passa o\nendpoint para quem religou.\n"
          },
          "disabled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventTypeName"
            }
          },
          "failing_since": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_success_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_failure_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "secret_rotated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "previous_secret_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_by": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "user",
                  "api_key"
                ]
              },
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookEndpointWithSecret": {
        "description": "Repetir o pedido com a mesma `Idempotency-Key` devolve o endpoint com\n`secret: null` e `secret_redacted: true`: o segredo só fica no cofre. Perdeu\no segredo? Use `rotate-secret`.\n",
        "allOf": [
          {
            "$ref": "#/components/schemas/WebhookEndpoint"
          },
          {
            "type": "object",
            "required": [
              "secret"
            ],
            "properties": {
              "secret": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/WebhookSecret"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "secret_redacted": {
                "type": "boolean"
              }
            }
          }
        ]
      },
      "WebhookDeliveryStatus": {
        "type": "string",
        "enum": [
          "pending",
          "paused",
          "delivering",
          "succeeded",
          "failed",
          "cancelled"
        ]
      },
      "WebhookDeliveryError": {
        "type": [
          "string",
          "null"
        ],
        "description": "`dns_or_address_refused`: a conexão com o seu servidor não chegou a ser\nestabelecida (o nome não resolveu, resolveu para um endereço que não pode\nreceber, a porta recusou ou não respondeu, ou o TLS falhou). O Preflow não\ndiz qual, para o log não revelar nomes e portas da rede.\n`timeout` e `connection_failed`: depois de a conexão TLS existir, a\nresposta demorou mais de 10 s ou a conexão caiu.\n`event_scope_missing`: a chave que criou o endpoint não tem o acesso de\nleitura do tipo do evento; a entrega foi cancelada.\n",
        "enum": [
          null,
          "timeout",
          "dns_or_address_refused",
          "connection_failed",
          "redirect_not_followed",
          "http_error",
          "invalid_response",
          "no_secret",
          "lease_expired",
          "endpoint_disabled",
          "event_scope_missing",
          "delivery_failed"
        ]
      },
      "WebhookDelivery": {
        "type": "object",
        "required": [
          "id",
          "endpoint_id",
          "event_id",
          "event_type",
          "status",
          "attempts",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "endpoint_id": {
            "type": "string",
            "format": "uuid"
          },
          "event_id": {
            "type": "string",
            "example": "evt_9b2f0c1d4e5a46b7a8c9d0e1f2a3b4c5"
          },
          "event_type": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/WebhookDeliveryStatus"
          },
          "attempts": {
            "type": "integer"
          },
          "next_attempt_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_attempt_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_status_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_error": {
            "$ref": "#/components/schemas/WebhookDeliveryError"
          },
          "last_duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "succeeded_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "attempt_log": {
            "type": "array",
            "description": "Últimas 12 tentativas (status, código HTTP e tempo).",
            "items": {
              "type": "object",
              "properties": {
                "at": {
                  "type": "string",
                  "format": "date-time"
                },
                "attempt": {
                  "type": "integer"
                },
                "status_code": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "error": {
                  "$ref": "#/components/schemas/WebhookDeliveryError"
                },
                "duration_ms": {
                  "type": "integer"
                }
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "description": "Envelope de todo webhook. Deduplique pelo `id` (o mesmo do cabeçalho `webhook-id`).",
        "required": [
          "id",
          "type",
          "created_at",
          "workspace_id",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^evt_[0-9a-f]{32}$"
          },
          "type": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "workspace_id": {
            "type": "string",
            "format": "uuid"
          },
          "data": {
            "type": "object"
          }
        }
      },
      "WebhookEventWithDeliveries": {
        "allOf": [
          {
            "$ref": "#/components/schemas/WebhookEvent"
          },
          {
            "type": "object",
            "properties": {
              "deliveries": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "endpoint_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "status": {
                      "$ref": "#/components/schemas/WebhookDeliveryStatus"
                    },
                    "attempts": {
                      "type": "integer"
                    },
                    "last_status_code": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "succeeded_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "WhatsAppMessageEventData": {
        "type": "object",
        "required": [
          "id",
          "conversation_id",
          "direction",
          "status",
          "type",
          "from",
          "to",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Id da mensagem."
          },
          "conversation_id": {
            "type": "string",
            "format": "uuid"
          },
          "direction": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "received",
              "pending",
              "sent",
              "delivered",
              "read",
              "failed"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "template",
              "image",
              "audio",
              "video",
              "document",
              "sticker"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "description": "E.164. Na recebida é o contato; na enviada, a linha."
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "description": "E.164. Na recebida é a linha; na enviada, o contato."
          },
          "media": {
            "type": [
              "object",
              "null"
            ],
            "description": "Baixe o arquivo pela API de WhatsApp com o `id`.",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "type": {
                "type": "string"
              },
              "mime_type": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "file_name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "template": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "language": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "lead_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "contact_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WhatsAppMessageSentData": {
        "allOf": [
          {
            "$ref": "#/components/schemas/WhatsAppMessageEventData"
          },
          {
            "type": "object",
            "required": [
              "origin"
            ],
            "properties": {
              "origin": {
                "type": "string",
                "enum": [
                  "api",
                  "cadence",
                  "ai",
                  "human",
                  "whatsapp_app"
                ],
                "description": "`whatsapp_app`: enviada pelo app do WhatsApp Business do celular."
              },
              "client_reference": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Só com `origin = api`."
              },
              "api_message_id": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Só com `origin = api`."
              }
            }
          }
        ]
      },
      "WhatsAppMessageStatusData": {
        "allOf": [
          {
            "$ref": "#/components/schemas/WhatsAppMessageEventData"
          },
          {
            "type": "object",
            "required": [
              "previous_status",
              "status_at"
            ],
            "properties": {
              "previous_status": {
                "type": "string"
              },
              "status_at": {
                "type": "string",
                "format": "date-time"
              },
              "failure": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "window_closed",
                      "invalid_recipient",
                      "recipient_opted_out",
                      "not_delivered_by_whatsapp",
                      "rate_limited",
                      "template_error",
                      "media_error",
                      "delivery_failed"
                    ]
                  }
                }
              }
            }
          }
        ]
      },
      "WhatsAppTemplateStatusData": {
        "type": "object",
        "required": [
          "id",
          "name",
          "language",
          "provider",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider": {
            "type": "string",
            "enum": [
              "meta",
              "twilio"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "approved",
              "pending",
              "rejected",
              "archived"
            ]
          },
          "previous_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "WebhookTestData": {
        "type": "object",
        "required": [
          "endpoint_id",
          "message"
        ],
        "properties": {
          "endpoint_id": {
            "type": "string",
            "format": "uuid"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Pedido inválido.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Sem chave, chave inválida ou revogada.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Plano sem API, workspace arquivado ou escopo insuficiente.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Recurso não encontrado neste workspace.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "Idempotency-Key em conflito, em execução ou com resultado incerto.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "Créditos insuficientes.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "O pedido está certo, mas não pode ser atendido (código em error.code; ex. janela fechada, contato que pediu para não ser contatado).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Limite de pedidos atingido.",
        "headers": {
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "OutcomeUnknown": {
        "description": "Resultado incerto (por exemplo, um serviço não respondeu). Nada é\nexecutado de novo com a mesma Idempotency-Key: consulte o recurso\n(`resource_id`) antes de tentar com outra chave.\n",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OutcomeUnknown"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Indisponível no momento; tente de novo.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}