{
  "openapi": "3.1.0",
  "info": {
    "title": "Preflow public API",
    "version": "1.0.0",
    "summary": "Connect your company's systems to Preflow.",
    "description": "REST API that lets your company's systems (ERP, app, e-commerce, in-house CRM)\ntalk to Preflow. Guides at https://developers.preflow.sale/en/.\n\n- Authenticate with the workspace secret key (`Authorization: Bearer pf_live_…`).\n- Every POST, PATCH and DELETE requires an `Idempotency-Key`.\n- Dates in ISO-8601 (UTC), phone numbers in E.164, ids as UUIDs.\n- Errors always use the format `{ \"error\": { code, message, request_id, retryable, details } }`.\n",
    "contact": {
      "name": "Preflow",
      "url": "https://preflow.sale"
    }
  },
  "servers": [
    {
      "url": "https://api.preflow.sale",
      "description": "Production"
    },
    {
      "url": "https://api-hml.preflow.sale",
      "description": "Staging"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Conta",
      "description": "The key and its workspace.",
      "x-displayName": "Account"
    },
    {
      "name": "WhatsApp",
      "description": "Lines, templates, 24-hour window, sending, status, history and media.",
      "x-displayName": "WhatsApp"
    },
    {
      "name": "Arquivos",
      "description": "Upload files to send as media.",
      "x-displayName": "Files"
    },
    {
      "name": "Leads",
      "description": "Create a lead (enters as inbound), search leads and read the timeline.",
      "x-displayName": "Leads"
    },
    {
      "name": "Conversões",
      "description": "Inbound conversion: a person asked to be contacted on your website, app or system.\nIt follows the same path as a Preflow form (MQL, attribution, Inbound\ncadence). Guide: https://developers.preflow.sale/en/guides/website-leads/\n",
      "x-displayName": "Conversions"
    },
    {
      "name": "Contas e funis",
      "description": "Stage per funnel, intermediate stage, owners, qualification and Customer/Churn.",
      "x-displayName": "Accounts & funnels"
    },
    {
      "name": "Cadências",
      "description": "List cadences, enroll a lead and stop a lead's cadence.",
      "x-displayName": "Cadences"
    },
    {
      "name": "Reuniões",
      "description": "Scheduled meetings (without calendar mirrors).",
      "x-displayName": "Meetings"
    },
    {
      "name": "Webhooks",
      "description": "Endpoints that receive Preflow's notifications, signed with the Standard\nWebhooks scheme. Guide at https://developers.preflow.sale/en/guides/webhooks/.\n",
      "x-displayName": "Webhooks"
    },
    {
      "name": "Eventos",
      "description": "Event catalog and lookup of an event that was already emitted.",
      "x-displayName": "Events"
    }
  ],
  "paths": {
    "/v1/me": {
      "get": {
        "tags": [
          "Conta"
        ],
        "operationId": "getMe",
        "summary": "Key workspace, scopes and limits",
        "description": "Any valid key can call this. Use it to check your integration's setup.",
        "responses": {
          "200": {
            "description": "Key context.",
            "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": "This specification",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 specification of the API.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/whatsapp/senders": {
      "get": {
        "tags": [
          "WhatsApp"
        ],
        "operationId": "listWhatsAppSenders",
        "summary": "Workspace WhatsApp lines",
        "description": "Numbers the API can use in `from`: the number of each active person in the\nworkspace and the own number of each active AI agent. A person's WhatsApp\nBusiness on their phone is their personal phone and is not available to the API.\n",
        "x-required-scope": "whatsapp:read",
        "responses": {
          "200": {
            "description": "Lines.",
            "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": "WhatsApp templates",
        "description": "By default, only templates approved for the workspace's provider.",
        "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": "24-hour window with a contact",
        "description": "Open: you can send text and media. Closed: approved templates only.\nThe window is per line: it counts the contact's last message to that line.\n",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "+5511999998888"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Line id. If omitted, the key's default line.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Window state.",
            "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": "Prepare a file upload",
        "description": "Returns a URL to upload the bytes with `PUT` (valid for 2 hours). Then\nuse the `id` in `media.file_id` when sending the message. Up to 16 MB; the\nuploaded file must match the declared size and type. 60 per minute and\n1,000 per day per key; the file is deleted after 30 days.\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": "Size in bytes."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "File registered and upload URL.",
            "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": "Send a WhatsApp message",
        "description": "Sends text, an approved template or media to a phone number or a lead,\nthrough a workspace line. It goes through the same rules as any Preflow\nsend (privacy, paused or closed contact, plan and credits, line quality).\nOutside the 24-hour window, approved templates only.\n\n- A number that is not a lead yet becomes a **contact** (not a lead).\n- The message doesn't take the conversation away from whoever is handling\n  it (AI or a person) and doesn't count in the touchpoint dashboards.\n- Billing: Preflow's WhatsApp price table; a provider rejection refunds the credit.\n- `202` with `status: unknown`: the outcome is uncertain. Nothing is\n  resent; check `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": "Sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WhatsAppMessage"
                }
              }
            }
          },
          "202": {
            "description": "Uncertain outcome; nothing will be resent.",
            "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": "History with a contact",
        "description": "All messages with the phone number, from every source, newest first.",
        "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": "A page of messages.",
            "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": "A message and its delivery status",
        "description": "Accepts the `id` returned by the send call (status `sending`, `sent`,\n`delivered`, `read`, `failed` or `unknown`) or the `id` of a message from the history.\n",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Message.",
            "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": "Download a message's media",
        "x-required-scope": "whatsapp:read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The media bytes, with the original Content-Type.",
            "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": "Create a lead (inbound entry)",
        "description": "The lead enters as **inbound** and follows the workspace's Inbound settings\n(cadence, owner and notification to whoever handles it). Provide `email` or\n`phone` (or both).\n\n- A lead with the same email or phone already exists: returns that lead\n  (`200`, `created: false`) without changing anything on it. A lead that is\n  already being worked (in a cadence, lost, won or in prospecting) is never\n  reopened.\n- The lead snapshot (`lead`) is only returned to keys with `leads:read`;\n  without it, the response only includes `lead_id`.\n- Dedicated limit: 60 leads per minute per key.\n- `external_id` is the lead's id in your system, unique in the workspace:\n  sending the same `external_id` again returns the same lead without\n  changing anything.\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": "The lead already existed (same external_id, email or phone).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadCreateResult"
                }
              }
            }
          },
          "201": {
            "description": "Lead created.",
            "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": "Search and list leads",
        "description": "With no filter, lists every lead by update time (oldest first). Use\n`updated_since` to sync only what changed. Merged leads are not\nreturned.\n",
        "parameters": [
          {
            "name": "email",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "email"
            }
          },
          {
            "name": "phone",
            "in": "query",
            "description": "Phone number in E.164.",
            "schema": {
              "type": "string",
              "example": "+5511999998888"
            }
          },
          {
            "name": "external_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "description": "Only leads updated at or after this date (ISO-8601).",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of 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": "Record an inbound conversion",
        "description": "Use it when a **person asked to be contacted** (a form on your website, a landing\npage, an app, your own chat). The conversion follows the same path as a Preflow\nform: it becomes an MQL, counts in attribution and starts the workspace's\nInbound cadence. To sync records from your system, use `POST /v1/leads`.\n\n- **MQL by default.** Send `\"qualified\": false` to record it as a contact only\n  (no lead, owner or cadence). With `form_id`, that Preflow form's MQL rules\n  decide.\n- **Existing lead** (same email, phone or LinkedIn): the conversion goes into\n  its history and the MQL updates the account. A lost, won, archived or\n  already-handled lead is never reopened (`result: lead_unchanged`).\n- **`submission_id`** is the conversion's id in your system, unique in the\n  workspace. Sending it again returns the same conversion, with any\n  `Idempotency-Key`; with different content, `409 submission_id_conflict`.\n  After a `202`, repeat with the same `submission_id`: the conversion resumes\n  without duplicating.\n- `campaign` (the slug of a Preflow campaign) and `attribution.utm_campaign`\n  reach the Inbound routing rules.\n- Dedicated limit: 120 conversions per minute per key.\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": "Conversion recorded on a lead that already existed, as a contact only, or the\nsame conversion (`submission_id`) already recorded before.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundSubmission"
                }
              }
            }
          },
          "201": {
            "description": "Conversion recorded and lead created.",
            "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": "Retrieve a conversion",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The conversion.",
            "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": "Retrieve a lead",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The 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": "Lead timeline",
        "description": "Newest first. Public types only (listed in `ActivityType`); internal\nrecords are not returned.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of activities.",
            "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": "Enroll the lead in a cadence",
        "description": "Same enrollment as in the app, with the same rejections (lead already in a\ncadence, engagement pause, lead that already had a meeting, lost-lead\ncooldown, cadence whose steps would all be created cancelled). The steps are\ncarried out by the pre-sales owner of the lead's account. Dedicated limit:\n60 enrollments per minute per key.\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 from GET /v1/cadences."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lead enrolled.",
            "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": "Stop the lead's cadence",
        "description": "Cancels the cadence steps that are still open for **this lead**. Other\npeople on the same account stay in their cadences; an ongoing conversation\nand manually scheduled follow-ups also continue. Anything in the send queue\nis cancelled; anything the provider already received is not recalled. With\nno open cadence, returns `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": "Result.",
            "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": "Workspace cadences",
        "description": "Cadences that can receive leads (excluding archived and system cadences).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of cadences.",
            "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": "List accounts",
        "description": "By update time (oldest first). Use `updated_since` to sync only what changed.",
        "parameters": [
          {
            "name": "updated_since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of accounts.",
            "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": "Retrieve an account",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The account.",
            "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": "Funnels and stages",
        "responses": {
          "200": {
            "description": "All funnels in the 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": "List meetings",
        "description": "Ordered by meeting date. Blocks copied from Outlook or Google calendars\nare not meetings and are never returned.\n",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "Meetings on or after this date.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Meetings before this date.",
            "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": "A page of meetings.",
            "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": "Retrieve a meeting",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The meeting.",
            "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": "Event types an endpoint can subscribe to",
        "responses": {
          "200": {
            "description": "Catalog of available events.",
            "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": "An event emitted in the last 30 days, with its deliveries",
        "description": "The event carries the resource: besides `webhooks:manage`, the key needs the\nread scope of the event type's module (`whatsapp:read`, `leads:read`,\n`accounts:read` or `meetings:read`); without it, `403 insufficient_scope`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EventId"
          }
        ],
        "responses": {
          "200": {
            "description": "The event (same envelope the webhook carries) and its deliveries.",
            "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": "Workspace endpoints",
        "responses": {
          "200": {
            "description": "Up to 10 endpoints, without the secret.",
            "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": "Create an endpoint",
        "description": "The response includes the `whsec_…` secret **only once**. Store it in the\nsecrets vault of the server that receives the webhooks. Up to 10 endpoints\nper workspace and 30 creations per hour (then `429`).\n\nEach event carries the resource (message text, phone number, lead): the key\nalso needs the read scope of the module of each subscribed type\n(`whatsapp.*` → `whatsapp:read`, `lead.*` → `leads:read`, `account.*` →\n`accounts:read`, `meeting.*` → `meetings:read`); without it,\n`403 insufficient_scope` with `details.required_scope`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEndpointCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Endpoint created, with the secret.",
            "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": "Retrieve an endpoint",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          }
        ],
        "responses": {
          "200": {
            "description": "The endpoint, without the secret.",
            "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": "Update, disable or re-enable an endpoint",
        "description": "Omitted fields don't change. `status: \"disabled\"` stops deliveries\nimmediately and cancels pending ones; `status: \"active\"` re-enables it and\nresets the failure count. Changing `url` or `events`, or re-enabling,\nrequires the read scope of every type the endpoint will receive (see\nendpoint creation).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEndpointUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated endpoint.",
            "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": "Delete an endpoint",
        "description": "The endpoint's secret and delivery log are deleted.",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Endpoint deleted.",
            "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": "Generate a new secret",
        "description": "The previous secret keeps signing for 24 hours: during that period the\n`webhook-signature` header carries both signatures, so your receiver can\nswitch secrets without missing events. Another rotation within those 24\nhours returns `409 webhook_rotation_in_progress`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "The new secret (shown only once).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "secret",
                    "previous_secret_expires_at"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "secret": {
                      "description": "`null` (with `secret_redacted: true`) when the request is repeated with the same `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": "Send a test event",
        "description": "Creates a `webhook.test` event for this endpoint only and delivers it\nthrough the normal path (signed, with retries). Track it in the deliveries\nlist. Up to 5 tests per minute per endpoint (then `429`).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/EndpointId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "202": {
            "description": "Test event queued.",
            "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": "Endpoint delivery log (30 days)",
        "description": "Newest first. Stores the status, HTTP code and duration of each attempt, never the response body.",
        "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": "A page of deliveries.",
            "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": "Retry a delivery now",
        "description": "Works for deliveries that are pending, failed or cancelled; a delivery that\nalready succeeded is rejected (`409 webhook_delivery_already_succeeded`).\nThe endpoint must be active. Up to 10 retries per minute per endpoint\n(then `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": "Delivery queued to run now.",
            "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": "Secret key created in Settings → Integrations → API & webhooks.\nIt is shown only once, when created. Store it in your server's secrets\nvault and never use it in a browser or mobile app.\n"
      }
    },
    "headers": {
      "X-Request-Id": {
        "description": "Request identifier. Include it when contacting support.",
        "schema": {
          "type": "string",
          "example": "req_6f1c2b0e8a7d4c3b9e2f1a0d5c4b3a29"
        }
      },
      "RateLimit-Limit": {
        "description": "Requests allowed in the window.",
        "schema": {
          "type": "integer",
          "example": 600
        }
      },
      "RateLimit-Remaining": {
        "description": "Requests still available in the window.",
        "schema": {
          "type": "integer",
          "example": 599
        }
      },
      "RateLimit-Reset": {
        "description": "Seconds until the window resets.",
        "schema": {
          "type": "integer",
          "example": 42
        }
      },
      "Retry-After": {
        "description": "Seconds to wait before retrying.",
        "schema": {
          "type": "integer",
          "example": 42
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "A unique value per operation (e.g. a UUID). Repeating the same request with\nthe same key within 24 hours returns the same response without running it again.\n",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "description": "Items per page (1 to 100).",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "description": "The `next_cursor` value from the previous page.",
        "schema": {
          "type": "string"
        }
      },
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "EndpointId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Endpoint id.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "EventId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Event id (`evt_…`), the same as the `webhook-id` header.",
        "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": "Stable code. Catalog at https://developers.preflow.sale/en/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 when the same request may succeed later."
              },
              "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 in `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": "The person's default line."
          },
          "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 in `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": "Fill in all of them in `template.variables`, by name or by position (`\"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": "Provide `to` or `lead_id` (with both, `to` must be one of the lead's phone\nnumbers), and exactly one of `text`, `template` and `media`.\n",
        "properties": {
          "to": {
            "type": "string",
            "description": "Phone number in E.164.",
            "example": "+5511999998888"
          },
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "from": {
            "type": "string",
            "format": "uuid",
            "description": "Line id. If omitted, the key's default line."
          },
          "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": "Name of the contact created when the number is not a lead."
          },
          "client_reference": {
            "type": "string",
            "maxLength": 200,
            "description": "Your id; returned in the status and in 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": "Message id in the history."
          },
          "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": "Who sent it (outbound messages only)."
          },
          "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": "Provide `email` or `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": "The conversion's id in your system, unique in the workspace (visible ASCII, no spaces)."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the person converted. Defaults to now. Up to 30 days in the past."
          },
          "answers": {
            "type": "array",
            "maxItems": 40,
            "description": "Form answers, stored on the conversion and on a new lead. With `form_id`,\n`key` is the field id in the Preflow form and its MQL rules apply. Up to\n64 KB in total; text with a control character (other than tab and line\nbreak) is rejected with `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 records it as a contact only. Ignored when the `form_id` form has MQL rules."
          },
          "form_id": {
            "type": "string",
            "format": "uuid",
            "description": "Published Preflow form whose rules, funnel and campaign apply."
          },
          "funnel_id": {
            "type": "string",
            "format": "uuid",
            "description": "The lead's funnel. Defaults to the form's funnel or the Inbound settings."
          },
          "campaign": {
            "type": "string",
            "maxLength": 100,
            "description": "Slug of a Preflow campaign."
          },
          "source": {
            "type": "string",
            "maxLength": 80,
            "description": "Free label from your system (e.g. website), stored on the conversion."
          },
          "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": "Meta's _fbc cookie. With fbclid, fbc or fbp, the conversion is sent to Meta's Conversions API when Meta is connected."
              },
              "fbp": {
                "type": "string",
                "maxLength": 500,
                "description": "Meta's _fbp cookie."
              },
              "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": "The text the person accepted."
              },
              "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` new lead; `lead_updated` an existing lead got the missing data;\n`lead_unchanged` lost, won, archived or already-handled lead, only recorded;\n`contact_only` not an MQL, contact only.\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": "The MQL was recorded now (false when the lead was already higher or a person decided otherwise)."
          },
          "matched_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the existing lead was found. Only for keys with `leads:read`."
          },
          "inbound_cadence": {
            "type": [
              "object",
              "null"
            ],
            "description": "What the Inbound settings did. null when nothing started.",
            "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": "The `form_id` form, when sent."
          },
          "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": "Only for keys with `leads:read`."
          }
        }
      },
      "LeadCreate": {
        "type": "object",
        "additionalProperties": false,
        "description": "Provide `email` or `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": "The lead's id in your system. Unique in the workspace."
          },
          "source": {
            "type": "string",
            "maxLength": 80,
            "description": "Free-form label from your system (e.g. erp), stored with the entry."
          }
        }
      },
      "LeadCreateResult": {
        "type": "object",
        "required": [
          "lead_id",
          "created",
          "matched_by",
          "inbound_cadence"
        ],
        "properties": {
          "lead_id": {
            "type": "string",
            "format": "uuid"
          },
          "lead": {
            "$ref": "#/components/schemas/Lead",
            "description": "Only for keys with `leads:read`."
          },
          "created": {
            "type": "boolean"
          },
          "matched_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the existing lead was found (external_id, email, phone...). Only for keys with `leads:read`."
          },
          "inbound_cadence": {
            "type": [
              "object",
              "null"
            ],
            "description": "What the Inbound settings did. null when the lead was already being worked.",
            "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 once Preflow has normalized it."
          },
          "additional_phones": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "company": {
            "type": [
              "string",
              "null"
            ]
          },
          "position": {
            "type": [
              "string",
              "null"
            ]
          },
          "linkedin_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "description": "Contact lifecycle.",
            "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": "How the lead first came in (never changes)."
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "description": "Acquisition channel."
          },
          "loss_reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Only when status is 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": "Fixed funnel stage.",
        "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": "Account marked as Customer."
          },
          "is_churn": {
            "type": "boolean",
            "description": "Account marked as Churn."
          },
          "owners": {
            "type": "object",
            "required": [
              "pre_sales",
              "sales"
            ],
            "properties": {
              "pre_sales": {
                "$ref": "#/components/schemas/ProfileRef"
              },
              "sales": {
                "$ref": "#/components/schemas/ProfileRef"
              }
            }
          },
          "funnels": {
            "type": "array",
            "description": "One entry per funnel the account is in.",
            "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 when the account left the board (Churn leaves every column; Customer stays only in Sales)."
                },
                "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": "Stages the workspace created inside a fixed stage.",
            "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": "Steps created and open."
          },
          "born_cancelled_tasks": {
            "type": "integer",
            "description": "Steps that were created already cancelled (e.g. a channel with no contact info)."
          },
          "operator_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Who carries out the steps."
          },
          "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 or 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": "Signing secret. Shown only on creation and rotation.",
        "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://`, without username and password. Internal, private or Preflow addresses are rejected.",
            "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`: the workspace's plan doesn't include the API; deliveries are kept and sent once the plan is restored."
          },
          "disabled_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "manual",
              "failing",
              "creator_lost_access",
              null
            ],
            "description": "`failing`: failed for 3 days in a row. `creator_lost_access`: whoever created it (the person or the key) no\nlonger administers the workspace. In both cases the admins are notified; re-enabling transfers the\nendpoint to whoever re-enabled it.\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": "Repeating the request with the same `Idempotency-Key` returns the endpoint with\n`secret: null` and `secret_redacted: true`: the secret is kept only in the vault.\nLost the secret? 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`: the connection to your server was never\nestablished (the name didn't resolve, it resolved to an address that can't\nreceive, the port refused or didn't answer, or TLS failed). Preflow doesn't\nsay which, so the log doesn't reveal network names and ports.\n`timeout` and `connection_failed`: after the TLS connection was established,\nthe response took longer than 10 s or the connection dropped.\n`event_scope_missing`: the key that created the endpoint doesn't have the\nread scope for the event type; the delivery was cancelled.\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": "Last 12 attempts (status, HTTP code and duration).",
            "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 of every webhook. Deduplicate by `id` (the same as the `webhook-id` header).",
        "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": "Message id."
          },
          "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. On inbound messages it's the contact; on outbound messages, the line."
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "description": "E.164. On inbound messages it's the line; on outbound messages, the contact."
          },
          "media": {
            "type": [
              "object",
              "null"
            ],
            "description": "Download the file through the WhatsApp API using the `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`: sent from the WhatsApp Business app on the phone."
              },
              "client_reference": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Only when `origin = api`."
              },
              "api_message_id": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Only when `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": "Invalid request.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid or revoked key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Plan without API access, archived workspace or insufficient scope.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found in this workspace.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "Idempotency-Key conflict, still running or with an uncertain outcome.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "Insufficient credits.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "The request is valid but can't be fulfilled (code in error.code; e.g. closed window, contact who asked not to be contacted).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit reached.",
        "headers": {
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "OutcomeUnknown": {
        "description": "Uncertain outcome (for example, a service didn't respond). Nothing is run\nagain with the same Idempotency-Key: check the resource (`resource_id`)\nbefore retrying with a different key.\n",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OutcomeUnknown"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Temporarily unavailable; try again.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}