{
  "openapi": "3.1.0",
  "info": {
    "title": "Baatzo API v1",
    "version": "1.1.0",
    "summary": "Send WhatsApp templates, manage contacts and campaigns, and get signed event webhooks.",
    "description": "API v1 sends one approved Utility or Authentication template to one recipient, reads its status, and posts signed status webhooks. It is part of the Starter, Growth and Pro plans. The full API adds contacts and consent, templates (read), campaigns, Marketing sends and event webhooks; it is part of Pro (and Enterprise), and on another plan its operations answer 403 plan_required with details.upgradeTo. Keys are made in the Baatzo web app under Settings, Developers. The human-readable reference is at https://api.baatzo.com/docs. Sandbox keys (bz_test_) work on every plan: their sends never reach WhatsApp and are never charged. The MCP server at https://api.baatzo.com/mcp offers the same operations to AI assistants (https://api.baatzo.com/docs/mcp.html)."
  },
  "servers": [{ "url": "https://api.baatzo.com", "description": "Live" }],
  "security": [{ "apiKey": [] }],
  "paths": {
    "/v1/messages": {
      "post": {
        "operationId": "sendMessage",
        "summary": "Send one approved template to one number",
        "description": "Needs the messages:send scope. The first attempt runs inside the request. Utility and Authentication templates on every paid plan. A Marketing template (including one Meta has moved to Marketing) needs the messages:send_marketing scope too, on Pro: the contact needs a recorded marketing consent (422 consent_required), an opt-out refuses (422 recipient_opted_out, details.purpose marketing), +1 numbers are refused (422 recipient_not_allowed, details.reason us_number), a number that was not on WhatsApp in the last 30 days is refused (422 recipient_unreachable), and outside the workspace's sending hours a Marketing send is refused (409 quiet_hours, details.retry_at), as campaigns wait for them. Marketing goes through Meta's Marketing Messages API, with the Cloud API as fallback, and Baatzo's marketing fee is taken from the credit. Authentication codes are never stored: Baatzo keeps them only in memory for the call to WhatsApp.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "1 to 255 visible ASCII characters. A repeat with the same key and body within 24 hours answers the first result and sends nothing; the same key with another body is refused.",
            "schema": { "type": "string", "minLength": 1, "maxLength": 255 }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SendMessage" },
              "examples": {
                "otp": {
                  "summary": "A login code",
                  "value": {
                    "to": "+919829012345",
                    "template": { "name": "login_code", "language": "en" },
                    "variables": { "body": { "code": "482913" } },
                    "reference": "ebyai-login-88213"
                  }
                },
                "marketing": {
                  "summary": "A Marketing template with an image header (messages:send_marketing, Pro)",
                  "value": {
                    "to": "+919829012345",
                    "template": { "name": "diwali_offer", "language": "en" },
                    "variables": { "body": { "name": "Asha", "code": "DIWALI20" }, "header": { "image": { "link": "https://cdn.example.com/diwali.jpg" } } },
                    "reference": "diwali-asha"
                  }
                },
                "report": {
                  "summary": "A report with a PDF header",
                  "value": {
                    "to": "+919829012345",
                    "template": { "name": "mock_test_report", "language": "en" },
                    "variables": {
                      "body": { "parent_name": "Asha", "student": "Ravi" },
                      "header": { "document": { "link": "https://reports.example.com/r/88213.pdf", "filename": "Mock test 4.pdf" } }
                    },
                    "reference": "ebyai-report-88213"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Accepted by WhatsApp, or refused by WhatsApp for good (status failed or withheld, with the explanation).",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SendResult" }, "example": {"id": "0193a4e2-7c1d-7b3e-9f20-5d8c1e4a6b71", "status": "accepted", "reference": "ebyai-login-88213", "error": null} } }
          },
          "202": {
            "description": "Not settled yet: queued for a retry (Utility and Marketing, never Authentication) or unknown after a timeout. The status webhook tells you how it ends.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SendResult" }, "example": {"id": "0193a4e2-7c1d-7b3e-9f20-5d8c1e4a6b71", "status": "queued", "reference": "ebyai-report-88213", "error": null} } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "503": { "$ref": "#/components/responses/RetryLater" }
        }
      }
    },
    "/v1/messages/{id}": {
      "get": {
        "operationId": "getMessage",
        "summary": "Read a message's status, charge and, on failure, the explanation",
        "description": "Needs the messages:read scope. Any message sent through the API in your workspace.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The message", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Message" }, "example": {"id": "0193a4e2-7c1d-7b3e-9f20-5d8c1e4a6b71", "status": "delivered", "status_rank": 5, "reference": "ebyai-login-88213", "template": {"name": "login_code", "language": "en", "category": "authentication"}, "created_at": "2026-11-25T10:00:00.000Z", "times": {"accepted_at": "2026-11-25T10:00:01.000Z", "sent_at": "2026-11-25T10:00:02.000Z", "delivered_at": "2026-11-25T10:00:04.000Z", "read_at": null, "failed_at": null}, "charge": {"category": "authentication", "baatzo_fee_paise": 2, "state": "chargeable", "meta_charge_estimate": {"amount_micro_rupees": "115000", "is_estimate": true}}, "error": null} } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/exports": {
      "post": {
        "operationId": "startExport",
        "summary": "Export everything in the workspace into one zip",
        "description": "Needs the data:export scope and an Idempotency-Key (8 to 100 letters, digits, - or _). Contacts, the consent ledger, messages, templates, invoices, campaigns and automations; emailed to the key's creator when ready, kept 7 days.",
        "parameters": [{ "name": "Idempotency-Key", "in": "header", "required": true, "schema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{8,100}$" } }],
        "requestBody": {
          "required": false,
          "content": { "application/json": { "schema": { "type": "object", "properties": { "everything": { "type": "boolean", "const": true } }, "additionalProperties": false }, "example": { "everything": true } } }
        },
        "responses": {
          "202": {
            "description": "Queued",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "export": { "$ref": "#/components/schemas/Export" } } }, "example": {"export": {"id": "0193a4f0-1b2c-7d3e-8f40-6a7b8c9d0e1f", "status": "queued", "everything": true, "contacts": null, "created_at": "2026-11-25T10:00:00.000Z", "completed_at": null, "expires_at": null, "download_url": null, "failure_reason": null}} } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "get": {
        "operationId": "listExports",
        "summary": "List exports, newest first",
        "description": "Needs the data:export scope.",
        "parameters": [
          { "name": "cursor", "in": "query", "schema": { "type": "string", "format": "uuid" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 20 } }
        ],
        "responses": {
          "200": {
            "description": "A page of exports",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "exports": { "type": "array", "items": { "$ref": "#/components/schemas/Export" } }, "next_cursor": { "type": ["string", "null"] } }
                },
                "example": {"exports": [{"id": "0193a4f0-1b2c-7d3e-8f40-6a7b8c9d0e1f", "status": "ready", "everything": true, "contacts": 1250, "created_at": "2026-11-25T10:00:00.000Z", "completed_at": "2026-11-25T10:02:10.000Z", "expires_at": "2026-12-02T10:02:10.000Z", "download_url": "/v1/exports/0193a4f0-1b2c-7d3e-8f40-6a7b8c9d0e1f/download", "failure_reason": null}], "next_cursor": null}
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/exports/{id}/download": {
      "get": {
        "operationId": "downloadExport",
        "summary": "Download a ready export",
        "description": "Needs the data:export scope. 409 export_not_ready while it is queued or building; 410 export_expired after its 7 days, or when it could not be made.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The zip", "content": { "application/zip": { "schema": { "type": "string", "format": "binary" }, "example": "(the zip file: contacts.csv, consent.csv, messages.csv, templates.csv, invoices/, campaigns.csv, automations.csv)" } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "410": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/consent-certificate": {
      "get": {
        "operationId": "getConsentCertificate",
        "summary": "A contact's consent certificate (PDF)",
        "description": "Needs the contacts:read scope. The contact's consent ledger: each opt-in and opt-out with its date, source, statement, IP and recorder where Baatzo has them. For your records, not legal advice.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The PDF", "content": { "application/pdf": { "schema": { "type": "string", "format": "binary" }, "example": "(the PDF: one page per contact, each opt-in and opt-out with its date, source and statement)" } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts": {
      "get": {
        "operationId": "listContacts",
        "summary": "List contacts, newest first",
        "description": "Full API (Pro). Needs the contacts:read scope. Search matches a name or a number; filter by tag, list or consent state.",
        "parameters": [
          { "$ref": "#/components/parameters/Cursor" },
          { "$ref": "#/components/parameters/Limit" },
          { "name": "q", "in": "query", "description": "Matches a name or a phone number", "schema": { "type": "string", "minLength": 1, "maxLength": 100 } },
          { "name": "tag_id", "in": "query", "schema": { "type": "string", "format": "uuid" } },
          { "name": "list_id", "in": "query", "schema": { "type": "string", "format": "uuid" } },
          { "name": "marketing", "in": "query", "schema": { "$ref": "#/components/schemas/ConsentState" } },
          { "name": "utility", "in": "query", "schema": { "$ref": "#/components/schemas/ConsentState" } }
        ],
        "responses": {
          "200": {
            "description": "A page of contacts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "contacts": { "type": "array", "items": { "$ref": "#/components/schemas/Contact" } }, "next_cursor": { "type": ["string", "null"] }, "total": { "type": "integer" } }
                },
                "example": {"contacts": [{"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "name": "Asha Verma", "phone": "+919829012345", "bsuid": null, "username": null, "attributes": {"city": "Jaipur"}, "source": "api", "consent": {"marketing": "granted", "utility": "granted", "marketing_opted_out_at": null}, "us_number": false, "unreachable_until": null, "last_message_at": null, "tags": [{"id": "0193b1c2-0000-7a00-8000-000000000001", "name": "VIP"}], "lists": [], "created_at": "2026-11-28T10:00:00.000Z", "updated_at": "2026-11-28T10:00:00.000Z"}], "next_cursor": null, "total": 1}
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "upsertContact",
        "summary": "Add a contact, or update the one with this number, and record consent",
        "description": "Full API (Pro). Needs the contacts:write scope and an Idempotency-Key. The contact with this phone (or WhatsApp user ID) is updated, or added with source api. Each consent grant needs how the person agreed (collected_via), the words they agreed to (statement) and when (captured_at). The contact is saved before the consent: when a grant is refused (an opt-out with no new evidence dated after it), the answer is 422 consent_refused with details.contact_id.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/UpsertContact" },
              "example": {
                "phone": "+919829012345",
                "name": "Asha Verma",
                "attributes": { "city": "Jaipur" },
                "consent": [{ "purpose": "marketing", "collected_via": "web_form", "statement": "Send me offers on WhatsApp.", "captured_at": "2026-11-28T15:30:00+05:30", "ip": "203.0.113.7" }]
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Added", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UpsertContactResult" } } } },
          "200": {
            "description": "Updated",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UpsertContactResult" }, "example": {"created": false, "contact": {"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "name": "Asha Verma", "phone": "+919829012345", "consent": {"marketing": "granted", "utility": "none", "marketing_opted_out_at": null}}, "consent_records": [{"id": "0193b1c3-1a2b-7c3d-8e4f-5a6b7c8d9e0f", "purpose": "marketing", "action": "grant", "source": "api", "collected_via": "web_form", "captured_at": "2026-11-28T10:00:00.000Z", "recorded_at": "2026-11-28T10:00:01.000Z"}]} } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}": {
      "get": {
        "operationId": "getContact",
        "summary": "Read a contact",
        "description": "Full API (Pro). Needs the contacts:read scope.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": { "description": "The contact", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "updateContact",
        "summary": "Change a contact's name, number, fields, tags or lists",
        "description": "Full API (Pro). Needs the contacts:write scope. Fields left out keep their value; null clears one. tag_ids and list_ids replace the contact's tags and lists. Consent is never changed here: use POST /v1/contacts/{id}/consents or /opt-out.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UpdateContact" }, "example": { "name": "Asha V.", "attributes": { "city": "Udaipur" } } } } },
        "responses": {
          "200": { "description": "The contact", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "delete": {
        "operationId": "deleteContact",
        "summary": "Erase a contact (DPDP erasure)",
        "description": "Full API (Pro). Needs the contacts:write scope. As in the web app: the contact, its tags, lists and files go for good. Its opt-outs stay as hashes, so a person who said stop is never messaged again.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "204": { "description": "Erased" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/tags": {
      "post": {
        "operationId": "tagContact",
        "summary": "Add tags to a contact",
        "description": "Full API (Pro). Needs the contacts:write scope. The tags must exist (GET /v1/tags).",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "required": ["tag_ids"], "properties": { "tag_ids": { "type": "array", "minItems": 1, "maxItems": 50, "items": { "type": "string", "format": "uuid" } } } }, "example": { "tag_ids": ["0193b1c2-0000-7a00-8000-000000000001"] } } } },
        "responses": {
          "200": { "description": "The contact", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/tags/{tagId}": {
      "delete": {
        "operationId": "untagContact",
        "summary": "Remove a tag from a contact",
        "description": "Full API (Pro). Needs the contacts:write scope.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }, { "name": "tagId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The contact", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/lists": {
      "post": {
        "operationId": "addContactToList",
        "summary": "Add a contact to a list",
        "description": "Full API (Pro). Needs the contacts:write scope. The list must exist (GET /v1/lists).",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "required": ["list_id"], "properties": { "list_id": { "type": "string", "format": "uuid" } } }, "example": { "list_id": "0193b1c2-0000-7a00-8000-0000000000a1" } } } },
        "responses": {
          "200": { "description": "The contact", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/lists/{listId}": {
      "delete": {
        "operationId": "removeContactFromList",
        "summary": "Remove a contact from a list",
        "description": "Full API (Pro). Needs the contacts:write scope.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }, { "name": "listId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The contact", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/consents": {
      "post": {
        "operationId": "recordConsent",
        "summary": "Record one consent grant or withdrawal",
        "description": "Full API (Pro). Needs the contacts:write scope and an Idempotency-Key. Recorded with source api, the key as the recorder. A grant needs collected_via, statement and captured_at (422 invalid_request names each missing one). A grant after an opt-out needs evidence dated after the opt-out, else 422 consent_refused.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/Id" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ConsentChange" },
              "example": { "purpose": "marketing", "action": "grant", "collected_via": "in_person", "statement": "Yes, send me offers on WhatsApp.", "captured_at": "2026-11-28T11:00:00+05:30", "note": "Signed at the Jaipur store" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "record": { "$ref": "#/components/schemas/ConsentRecord" }, "contact": { "$ref": "#/components/schemas/Contact" } } } } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/contacts/{id}/opt-out": {
      "post": {
        "operationId": "optOutContact",
        "summary": "Opt a contact out, as a STOP reply would",
        "description": "Full API (Pro). Needs the contacts:write scope. purpose is marketing (the default), utility or all. Recorded with source api.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "properties": { "purpose": { "type": "string", "enum": ["marketing", "utility", "all"], "default": "marketing" }, "note": { "type": "string", "maxLength": 500 } } }, "example": { "purpose": "marketing", "note": "Asked on a call" } } } },
        "responses": {
          "200": { "description": "Recorded", "content": { "application/json": { "schema": { "type": "object", "properties": { "records": { "type": "array", "items": { "$ref": "#/components/schemas/ConsentRecord" } }, "contact": { "$ref": "#/components/schemas/Contact" } } } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/tags": {
      "get": {
        "operationId": "listTags",
        "summary": "List the workspace's tags",
        "description": "Full API (Pro). Needs the contacts:read scope. Up to 500, by name.",
        "responses": {
          "200": {
            "description": "The tags",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "contacts": { "type": "integer" }, "created_at": { "type": "string", "format": "date-time" } } } } } }, "example": {"tags": [{"id": "0193b1c2-0000-7a00-8000-000000000001", "name": "VIP", "contacts": 42, "created_at": "2026-11-20T10:00:00.000Z"}]} } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/lists": {
      "get": {
        "operationId": "listLists",
        "summary": "List the workspace's contact lists",
        "description": "Full API (Pro). Needs the contacts:read scope. Up to 500, by name.",
        "responses": {
          "200": {
            "description": "The lists",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "lists": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "kind": { "type": "string", "enum": ["static", "segment"], "description": "segment: a saved filter, usable as segment_ids in a campaign" }, "created_at": { "type": "string", "format": "date-time" }, "updated_at": { "type": "string", "format": "date-time" } } } } } }, "example": {"lists": [{"id": "0193b1c2-0000-7a00-8000-0000000000a1", "name": "Diwali buyers", "kind": "static", "created_at": "2026-11-20T10:00:00.000Z", "updated_at": "2026-11-20T10:00:00.000Z"}]} } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/templates": {
      "get": {
        "operationId": "listTemplates",
        "summary": "List templates, newest first",
        "description": "Full API (Pro). Needs the templates:read scope. Read only: templates are written and submitted in the web app.",
        "parameters": [
          { "$ref": "#/components/parameters/Cursor" },
          { "$ref": "#/components/parameters/Limit" },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["draft", "pending", "approved", "rejected", "paused", "disabled", "all"], "default": "all" } },
          { "name": "category", "in": "query", "schema": { "type": "string", "enum": ["marketing", "utility", "authentication"] } },
          { "name": "name", "in": "query", "schema": { "type": "string", "pattern": "^[a-z0-9_]{1,512}$" } },
          { "name": "language", "in": "query", "schema": { "type": "string", "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$" } }
        ],
        "responses": {
          "200": {
            "description": "A page of templates",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "templates": { "type": "array", "items": { "$ref": "#/components/schemas/Template" } }, "next_cursor": { "type": ["string", "null"] } } } } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/templates/{id}": {
      "get": {
        "operationId": "getTemplate",
        "summary": "Read a template, with the version Meta reviewed",
        "description": "Full API (Pro). Needs the templates:read scope.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": {
            "description": "The template",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "template": { "$ref": "#/components/schemas/Template" } } }, "example": {"template": {"id": "0193a1b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "name": "diwali_offer", "language": "en", "category": "marketing", "status": "approved", "quality": "green", "sendable": true, "variables": ["name", "code"], "header": {"format": "image", "text": null}, "body": "Hi {{name}}, use {{code}} for 20% off this Diwali.", "footer": "Reply STOP to opt out", "buttons": [{"type": "url", "text": "Shop now"}], "rejected_reason": null, "created_at": "2026-11-20T10:00:00.000Z", "updated_at": "2026-11-21T08:00:00.000Z"}} } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/templates/{id}/status": {
      "get": {
        "operationId": "getTemplateStatus",
        "summary": "Read a template's review status only",
        "description": "Full API (Pro). Needs the templates:read scope. The template.status_changed event tells you when it moves.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": { "description": "The status", "content": { "application/json": { "schema": { "type": "object", "properties": { "template": { "$ref": "#/components/schemas/TemplateStatus" } } } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns": {
      "get": {
        "operationId": "listCampaigns",
        "summary": "List campaigns, newest first",
        "description": "Full API (Pro). Needs the campaigns:read scope.",
        "parameters": [
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["all", "draft", "active", "finished"], "default": "all" } },
          { "name": "cursor", "in": "query", "description": "next_cursor from the previous page", "schema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{8,200}$" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 30 } }
        ],
        "responses": {
          "200": { "description": "A page of campaigns", "content": { "application/json": { "schema": { "type": "object", "properties": { "campaigns": { "type": "array", "items": { "$ref": "#/components/schemas/Campaign" } }, "next_cursor": { "type": ["string", "null"] } } } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createCampaign",
        "summary": "Create a campaign draft",
        "description": "Full API (Pro). Needs the campaigns:write scope and an Idempotency-Key. From an approved Marketing or Utility template (Authentication is refused: send codes one by one with POST /v1/messages) and at least one list, segment or tag. It sends nothing: estimate, schedule or send it next.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateCampaign" },
              "example": {
                "name": "Diwali offer 2026",
                "template": { "name": "diwali_offer", "language": "en" },
                "audience": { "list_ids": ["0193b1c2-0000-7a00-8000-0000000000a1"] },
                "variables": { "name": { "source": "name", "fallback": "there" }, "code": { "source": "text", "fallback": "DIWALI20" } },
                "header_media": { "link": "https://cdn.example.com/diwali.jpg" }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The draft",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "campaign": { "$ref": "#/components/schemas/Campaign" }, "variables_needed": { "type": "array", "items": { "type": "string" } } } }, "example": {"campaign": {"id": "0193c0d1-2e3f-7a4b-8c5d-6e7f8a9b0c1d", "name": "Diwali offer 2026", "status": "draft", "template": {"id": "0193a1b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "name": "diwali_offer", "language": "en", "category": "marketing", "status": "approved"}, "number": {"id": "0193a0a0-0000-7000-8000-000000000001", "display_phone": "+91 98290 12345"}, "category": "marketing", "audience": {"list_ids": ["0193b1c2-0000-7a00-8000-0000000000a1"], "segment_ids": [], "tag_ids": []}, "variables": {"name": {"source": "name", "fallback": "there"}, "code": {"source": "text", "fallback": "DIWALI20"}}, "scheduled_at": null, "held_until": null, "recipients": null, "baatzo_fee_per_message_paise": null, "credit": {"reserved_paise": "0", "settled_paise": "0", "released_paise": "0", "held_paise": "0"}, "pause": null, "failure_reason": null, "started_at": null, "completed_at": null, "cancelled_at": null, "created_at": "2026-11-28T10:00:00.000Z", "updated_at": "2026-11-28T10:00:00.000Z"}, "variables_needed": ["name", "code"]} } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns/{id}": {
      "get": {
        "operationId": "getCampaign",
        "summary": "Read a campaign",
        "description": "Full API (Pro). Needs the campaigns:read scope.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": { "description": "The campaign", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CampaignResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns/{id}/stats": {
      "get": {
        "operationId": "getCampaignStats",
        "summary": "A campaign's results",
        "description": "Full API (Pro). Needs the campaigns:read scope. The same counters the web app shows.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": {
            "description": "The results",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "campaign_id": { "type": "string", "format": "uuid" }, "status": { "$ref": "#/components/schemas/CampaignStatus" }, "stats": { "$ref": "#/components/schemas/CampaignStats" } } }, "example": {"campaign_id": "0193c0d1-2e3f-7a4b-8c5d-6e7f8a9b0c1d", "status": "completed", "stats": {"recipients": 1200, "queued": 0, "sent": 1180, "delivered": 1150, "read": 900, "replied": 64, "held": 0, "failed": 20, "withheld": 0, "skipped": 0, "cancelled": 0, "skipped_by_reason": {}, "failed_by_reason": {"131026": 20}, "baatzo_fee_paise": "5750", "meta_charge_estimate": {"amount_micro_rupees": "992565000", "is_estimate": true}}} } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns/{id}/estimate": {
      "post": {
        "operationId": "estimateCampaign",
        "summary": "Estimate a campaign as it stands",
        "description": "Full API (Pro). Needs the campaigns:write scope. Who can get it, who is left out and why, Meta's charge (an estimate, at most), Baatzo's fee with GST, the messaging limit forecast, quiet hours and whether the credit covers it. Changes nothing.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": { "description": "The estimate", "content": { "application/json": { "schema": { "type": "object", "properties": { "estimate": { "$ref": "#/components/schemas/CampaignEstimate" } } } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns/{id}/schedule": {
      "post": {
        "operationId": "scheduleCampaign",
        "summary": "Schedule a campaign",
        "description": "Full API (Pro). Needs the campaigns:write scope and an Idempotency-Key. At least 5 minutes and at most 90 days ahead. Confirms the estimate and reserves the credit (recipients x Baatzo's fee) now: 402 insufficient_credit when it does not cover them, unless start_anyway is true, which starts with the part the credit covers. 422 nothing_to_send when nobody in the audience can get it.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/Id" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "required": ["scheduled_at"], "properties": { "scheduled_at": { "type": "string", "format": "date-time", "description": "ISO 8601 with its offset" }, "start_anyway": { "type": "boolean" } } }, "example": { "scheduled_at": "2026-12-05T10:00:00+05:30" } } } },
        "responses": {
          "200": { "description": "Scheduled", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CampaignResult" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns/{id}/send": {
      "post": {
        "operationId": "sendCampaign",
        "summary": "Send a campaign now",
        "description": "Full API (Pro). Needs the campaigns:write scope and an Idempotency-Key. The campaign is held for 30 seconds (status held, held_until), when POST /v1/campaigns/{id}/cancel still stops it with nothing sent; then it starts. The credit rules are the same as for schedule.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/Id" }],
        "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "properties": { "start_anyway": { "type": "boolean" } } }, "example": {} } } },
        "responses": {
          "200": { "description": "Held, then sending", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CampaignResult" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/campaigns/{id}/cancel": {
      "post": {
        "operationId": "cancelCampaign",
        "summary": "Cancel a campaign",
        "description": "Full API (Pro). Needs the campaigns:write scope. A draft, a held send or a scheduled campaign ends at once and its credit goes back. One that is sending stops after the messages Meta already has.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": { "description": "Cancelled or cancelling", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CampaignResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/webhook-endpoint": {
      "get": {
        "operationId": "getWebhookEndpoint",
        "summary": "The webhook endpoint and every event type",
        "description": "Full API (Pro). Needs the webhooks:manage scope. The address and the signing secret are set only in the web app (Settings, Developers), never with an API key. endpoint is null until an address is set.",
        "responses": {
          "200": {
            "description": "The endpoint and the event catalogue",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEndpointResult" }, "example": {"endpoint": {"id": "0193a9f0-1111-7222-8333-444455556666", "url": "https://your-server.example/baatzo-webhook", "status": "ACTIVE", "events": ["message.sent", "message.delivered", "message.read", "message.failed", "contact.opted_out"], "created_at": "2026-11-22T10:00:00.000Z", "updated_at": "2026-11-28T10:00:00.000Z", "previous_secret_expires_at": null, "failing": false}, "events": {"full_api": true, "upgrade_to": null, "types": [{"type": "contact.opted_out", "label": "A contact opted out", "full_api": true, "available": true}]}} } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/webhook-endpoint/events": {
      "put": {
        "operationId": "setWebhookEvents",
        "summary": "Choose the event types the endpoint takes",
        "description": "Full API (Pro). Needs the webhooks:manage scope. Replaces the list: at least one type, each once. 404 not_found until an address is set in the web app. Event types beyond message status need a plan with the full API (403 plan_required).",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "required": ["events"], "properties": { "events": { "type": "array", "minItems": 1, "items": { "$ref": "#/components/schemas/EventType" } } } }, "example": { "events": ["message.sent", "message.delivered", "message.read", "message.failed", "message.received", "contact.opted_out", "campaign.finished"] } } } },
        "responses": {
          "200": { "description": "Saved", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WebhookEndpointResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/webhook-deliveries": {
      "get": {
        "operationId": "listWebhookDeliveries",
        "summary": "The delivery log, newest first (30 days)",
        "description": "Full API (Pro). Needs the webhooks:manage scope.",
        "parameters": [
          { "$ref": "#/components/parameters/Cursor" },
          { "$ref": "#/components/parameters/Limit" },
          { "name": "status", "in": "query", "schema": { "$ref": "#/components/schemas/DeliveryStatus" } },
          { "name": "from", "in": "query", "description": "ISO 8601 with its offset", "schema": { "type": "string", "format": "date-time" } },
          { "name": "to", "in": "query", "description": "ISO 8601 with its offset", "schema": { "type": "string", "format": "date-time" } }
        ],
        "responses": {
          "200": { "description": "A page of deliveries", "content": { "application/json": { "schema": { "type": "object", "properties": { "deliveries": { "type": "array", "items": { "$ref": "#/components/schemas/Delivery" } }, "next_cursor": { "type": ["string", "null"] } } } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/webhook-deliveries/{id}": {
      "get": {
        "operationId": "getWebhookDelivery",
        "summary": "One delivery, with its payload and your server's answer",
        "description": "Full API (Pro). Needs the webhooks:manage scope. response_body is the first 2 KB of your server's last answer.",
        "parameters": [{ "$ref": "#/components/parameters/Id" }],
        "responses": {
          "200": {
            "description": "The delivery",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "delivery": { "allOf": [{ "$ref": "#/components/schemas/Delivery" }, { "type": "object", "properties": { "payload": { "type": ["object", "null"], "description": "The event exactly as it was posted" }, "response_body": { "type": ["string", "null"] } } }] } } } } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/webhook-deliveries/{id}/replay": {
      "post": {
        "operationId": "replayWebhookDelivery",
        "summary": "Send one delivery again",
        "description": "Full API (Pro). Needs the webhooks:manage scope and an Idempotency-Key. The same event (the same id), signed with a fresh timestamp, sent once with Baatzo-Replay: 1 and no retries.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/Id" }],
        "responses": {
          "202": { "description": "Queued", "content": { "application/json": { "schema": { "type": "object", "properties": { "queued": { "type": "integer", "const": 1 }, "delivery_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "example": {"queued": 1, "delivery_ids": ["0193c1aa-2b3c-7d4e-8f5a-6b7c8d9e0f1a"]} } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "mcp",
        "summary": "The Baatzo MCP server (Model Context Protocol, Streamable HTTP, stateless)",
        "description": "JSON-RPC messages of the Model Context Protocol. Tools: list_templates, send_template_message, get_message_status, list_contacts, upsert_contact, get_credit_balance, and on Pro get_contact, list_campaigns and create_campaign, each with the scope and limits of the matching API v1 operation. See https://api.baatzo.com/docs/mcp.html.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" }, "example": { "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_credit_balance", "arguments": {} } } } } },
        "responses": {
          "200": { "description": "The JSON-RPC answer", "content": { "application/json": { "schema": { "type": "object" }, "example": {"jsonrpc": "2.0", "id": 1, "result": {"content": [{"type": "text", "text": "{\"available_paise\":\"125000\",\"reserved_paise\":\"0\",\"available_rupees\":\"1250.00\",\"currency\":\"INR\",\"note\":\"Baatzo's fee per message comes from this credit; Meta bills its own charge to your WhatsApp account directly.\",\"sandbox\":false}"}], "structuredContent": {"available_paise": "125000", "reserved_paise": "0", "available_rupees": "1250.00", "currency": "INR", "note": "Baatzo's fee per message comes from this credit; Meta bills its own charge to your WhatsApp account directly.", "sandbox": false}}} } } },
          "202": { "description": "A notification, accepted" },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "webhooks": {
    "messageStatus": {
      "post": {
        "summary": "A status of a message sent through the API",
        "description": "Posted to your workspace's webhook URL for message.sent, message.delivered, message.read and message.failed, for messages sent through the API, when the endpoint subscribes to them (a new endpoint does). Signed with Baatzo-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of '<t>.<raw body>' keyed with your whsec_ secret>. Answer any 2xx within 5 seconds. Otherwise Baatzo retries after 1, 5, 15 and 30 minutes, 1, 2, 4 and 8 hours, and a last time 24 hours after the first attempt. Events can arrive out of order and more than once: use status_rank and id.",
        "parameters": [
          { "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } },
          {
            "name": "Baatzo-Replay",
            "in": "header",
            "required": false,
            "description": "1 when the delivery is a replay asked for in Settings, Developers: the same event (the same id), signed with a fresh timestamp, sent once with no retries.",
            "schema": { "type": "string", "enum": ["1"] }
          },
          {
            "name": "Baatzo-Sandbox",
            "in": "header",
            "required": false,
            "description": "1 when the event is a sandbox key's simulated message (the body also says \"sandbox\": true). Absent on live events.",
            "schema": { "type": "string", "enum": ["1"] }
          }
        ],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/StatusEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "messageReceived": {
      "post": {
        "summary": "message.received",
        "description": "Full API (Pro). A customer sent a message to one of your numbers. Posted only when the endpoint subscribes to message.received (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageReceivedEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "contactOptedIn": {
      "post": {
        "summary": "contact.opted_in",
        "description": "Full API (Pro). A contact's consent for marketing or utility became granted. Posted only when the endpoint subscribes to contact.opted_in (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactOptedInEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "contactOptedOut": {
      "post": {
        "summary": "contact.opted_out",
        "description": "Full API (Pro). A contact withdrew consent for marketing or utility (a STOP reply, the web app, the API or an import). Posted only when the endpoint subscribes to contact.opted_out (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContactOptedOutEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "templateStatusChanged": {
      "post": {
        "summary": "template.status_changed",
        "description": "Full API (Pro). Meta's review moved a template: approved, rejected, paused, disabled or recategorised. Posted only when the endpoint subscribes to template.status_changed (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TemplateStatusChangedEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "campaignFinished": {
      "post": {
        "summary": "campaign.finished",
        "description": "Full API (Pro). A campaign completed, was cancelled or failed, with its results at that moment. Posted only when the endpoint subscribes to campaign.finished (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CampaignFinishedEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "paymentLinkPaid": {
      "post": {
        "summary": "payment_link.paid",
        "description": "Full API (Pro). Razorpay reported a payment link paid in full. Posted only when the endpoint subscribes to payment_link.paid (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaymentLinkPaidEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    },
    "conversationAssigned": {
      "post": {
        "summary": "conversation.assigned",
        "description": "Full API (Pro). A person, a keyword rule or the round robin gave a chat to a team member. Posted only when the endpoint subscribes to conversation.assigned (PUT /v1/webhook-endpoint/events, or Settings, Developers). Signed, retried, logged and replayable exactly like the status events.",
        "parameters": [{ "name": "Baatzo-Signature", "in": "header", "required": true, "schema": { "type": "string" } }, { "name": "Baatzo-Replay", "in": "header", "required": false, "schema": { "type": "string", "enum": ["1"] } }],
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationAssignedEvent" } } } },
        "responses": { "200": { "description": "Any 2xx counts as delivered." } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer bz_live_<8-character prefix>_<32 characters> (bz_test_ for a sandbox key). Shown once when made; keep it on your server. Scopes: messages:send, messages:read, contacts:read, contacts:write and data:export on every paid plan; templates:read, campaigns:read, campaigns:write, messages:send_marketing and webhooks:manage only on a plan with the full API (Pro). The full API's contact routes need that plan too; the consent certificate does not. A missing scope answers 403 forbidden with details.reason missing_scope. A sandbox key holds messages:send and messages:read only: it is made with no other scope (400 sandbox_scope_not_allowed), and any other operation or MCP tool answers 403 forbidden with reason sandbox_scope."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "8 to 100 letters, digits, - or _. The same key and request within 24 hours answers the first result and does nothing again (422 idempotency_key_reused with another request, 409 idempotency_in_progress while the first still runs).",
        "schema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{8,100}$" }
      },
      "Id": { "name": "id", "in": "path", "required": true, "description": "An id that is not a UUID is simply not found (404)", "schema": { "type": "string", "format": "uuid" } },
      "Cursor": { "name": "cursor", "in": "query", "description": "next_cursor from the previous page", "schema": { "type": "string", "format": "uuid" } },
      "Limit": { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 } }
    },
    "responses": {
      "Error": { "description": "An error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "RateLimited": {
        "description": "Over the key's limit (10 sends a second with bursts to 20; 20 reads a second), or too many failed key checks from your address",
        "headers": {
          "Retry-After": { "schema": { "type": "integer" }, "description": "Seconds to wait" },
          "RateLimit-Limit": { "schema": { "type": "integer" }, "description": "The key's burst size for this kind of call (sent on every API v1 answer that passed the key check, as X-RateLimit-Limit too)" },
          "RateLimit-Remaining": { "schema": { "type": "integer" }, "description": "Calls left now (also X-RateLimit-Remaining)" },
          "RateLimit-Reset": { "schema": { "type": "integer" }, "description": "Seconds until the full burst is available again (also X-RateLimit-Reset)" }
        },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "RetryLater": {
        "description": "An Authentication send hit a temporary WhatsApp error. Baatzo does not retry codes: send a new code.",
        "headers": { "Retry-After": { "schema": { "type": "integer" } } },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "SendMessage": {
        "type": "object",
        "additionalProperties": false,
        "required": ["to", "template"],
        "properties": {
          "to": { "type": "string", "pattern": "^\\+[1-9]\\d{6,14}$", "description": "E.164. New keys send to Indian numbers only until the Owner adds countries." },
          "from": { "type": "string", "pattern": "^\\d{5,25}$", "description": "Meta's phone number ID of the sending number; needed only when the workspace has more than one." },
          "template": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name", "language"],
            "properties": { "name": { "type": "string" }, "language": { "type": "string", "description": "The template's language code, such as en or en_IN" } }
          },
          "variables": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "body": {
                "type": "object",
                "additionalProperties": { "type": "string", "maxLength": 1024 },
                "description": "Each variable by its name, or its number for a numbered template. For Authentication, the code as code (1 to 15 letters and digits)."
              },
              "header": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "text": { "type": "object", "additionalProperties": { "type": "string" } },
                  "document": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["link", "filename"],
                    "properties": {
                      "link": { "type": "string", "format": "uri", "maxLength": 2048, "description": "https, no user name or password. WhatsApp fetches it." },
                      "filename": { "type": "string", "maxLength": 240 }
                    }
                  },
                  "image": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["link"],
                    "description": "For a template with an image header (Utility or Marketing)",
                    "properties": { "link": { "type": "string", "format": "uri", "maxLength": 2048, "description": "https, no user name or password. WhatsApp fetches it." } }
                  },
                  "video": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["link"],
                    "description": "For a template with a video header (Utility or Marketing)",
                    "properties": { "link": { "type": "string", "format": "uri", "maxLength": 2048, "description": "https, no user name or password. WhatsApp fetches it." } }
                  }
                }
              },
              "buttons": {
                "type": "array",
                "maxItems": 10,
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "index": { "type": "integer", "minimum": 0 },
                    "url": { "type": "string", "description": "The end of a URL button's address" },
                    "copy_code": { "type": "string", "maxLength": 15 }
                  }
                }
              }
            }
          },
          "reference": { "type": "string", "maxLength": 64, "description": "Your own id, echoed in reads and webhooks" }
        }
      },
      "Status": { "type": "string", "enum": ["queued", "unknown", "accepted", "held", "sent", "delivered", "read", "failed", "withheld"] },
      "Explanation": { "type": "object", "properties": { "en": { "type": "string" }, "hi": { "type": "string" } } },
      "MessageError": {
        "type": ["object", "null"],
        "properties": {
          "code": { "type": ["integer", "null"], "description": "WhatsApp's error code" },
          "title": { "type": ["string", "null"] },
          "explanation": { "$ref": "#/components/schemas/Explanation" }
        }
      },
      "SendResult": {
        "type": "object",
        "required": ["id", "status"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "status": { "$ref": "#/components/schemas/Status" },
          "reference": { "type": ["string", "null"] },
          "error": { "$ref": "#/components/schemas/MessageError" },
          "wamid": { "type": ["string", "null"], "description": "Sandbox answers only: a made-up id starting wamid.SANDBOX" },
          "sandbox": { "type": "boolean", "description": "Present and true only for a sandbox key (bz_test_): nothing reached WhatsApp and nothing was charged." }
        }
      },
      "Charge": {
        "type": "object",
        "properties": {
          "category": { "type": ["string", "null"], "description": "WhatsApp's pricing category" },
          "baatzo_fee_paise": { "type": "integer", "description": "Baatzo's fee, in paise; 0 when WhatsApp does not charge" },
          "state": { "type": "string", "enum": ["pending", "chargeable", "waived"] },
          "meta_charge_estimate": {
            "type": "object",
            "properties": { "amount_micro_rupees": { "type": "string" }, "is_estimate": { "const": true } },
            "description": "Meta bills you directly; this is an estimate from Meta's published rate."
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "status": { "$ref": "#/components/schemas/Status" },
          "status_rank": { "type": "integer" },
          "reference": { "type": ["string", "null"] },
          "template": {
            "type": "object",
            "properties": { "name": { "type": "string" }, "language": { "type": "string" }, "category": { "type": "string", "enum": ["utility", "authentication", "marketing"] } }
          },
          "created_at": { "type": "string", "format": "date-time" },
          "times": { "type": "object", "additionalProperties": { "type": ["string", "null"], "format": "date-time" } },
          "charge": { "$ref": "#/components/schemas/Charge" },
          "error": { "$ref": "#/components/schemas/MessageError" },
          "wamid": { "type": ["string", "null"], "description": "Sandbox messages only" },
          "sandbox": { "type": "boolean", "description": "Present and true only for a sandbox key (bz_test_): nothing reached WhatsApp and nothing was charged." }
        }
      },
      "StatusEvent": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "description": "evt_..., the same on every retry of this event" },
          "type": { "type": "string", "enum": ["message.sent", "message.delivered", "message.read", "message.failed", "webhook.test"] },
          "created_at": { "type": "string", "format": "date-time" },
          "sandbox": { "type": "boolean", "description": "Present and true only for a sandbox key (bz_test_): nothing reached WhatsApp and nothing was charged." },
          "data": {
            "type": "object",
            "properties": {
              "message_id": { "type": "string", "format": "uuid" },
              "reference": { "type": ["string", "null"] },
              "wamid": { "type": ["string", "null"], "description": "Meta's message id (wamid.SANDBOX... for a sandbox message), for matching with Meta's own logs" },
              "sandbox": { "type": "boolean", "description": "Present and true only for a sandbox key (bz_test_): nothing reached WhatsApp and nothing was charged." },
              "status": { "$ref": "#/components/schemas/Status" },
              "status_rank": { "type": "integer", "description": "Higher is later: ignore an event whose rank is below one you have" },
              "charge": { "type": "object", "properties": { "category": { "type": ["string", "null"] }, "baatzo_fee_paise": { "type": "integer" }, "state": { "type": "string" } } },
              "error": { "type": ["object", "null"], "properties": { "code": { "type": ["integer", "null"] }, "title": { "type": ["string", "null"] } } }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "unauthenticated",
              "forbidden",
              "plan_required",
              "idempotency_key_required",
              "invalid_request",
              "template_not_found",
              "template_not_approved",
              "category_not_allowed",
              "recipient_not_allowed",
              "recipient_opted_out",
              "insufficient_credit",
              "sending_paused",
              "idempotency_key_reused",
              "request_in_progress",
              "rate_limited",
              "retry_later",
              "not_found",
              "idempotency_key_invalid",
              "idempotency_in_progress",
              "export_in_progress",
              "export_not_ready",
              "export_expired",
              "contact_exists",
              "consent_refused",
              "consent_required",
              "recipient_unreachable",
              "campaign_state",
              "nothing_to_send",
              "quiet_hours"
            ]
          },
          "message": { "type": "string" },
          "details": { "description": "For invalid_request, a list of { field, message } (with reason where the full API has one); otherwise an object or absent. On the full API, details.reason often names the precise cause, such as campaign_locked under campaign_state." }
        }
      },
      "ConsentState": { "type": "string", "enum": ["none", "granted", "withdrawn"] },
      "CollectedVia": {
        "type": "string",
        "enum": ["web_form", "paper_form", "whatsapp", "ctwa_ad", "in_person", "phone_call", "other"],
        "description": "How the person agreed: a web form, a paper form, on WhatsApp, a Click-to-WhatsApp ad, in person, on a phone call, or another way (say how in note)"
      },
      "ContactRef": {
        "type": ["object", "null"],
        "description": "The contact an event is about: the business's own customer data, never a hash",
        "properties": { "id": { "type": "string", "format": "uuid" }, "phone": { "type": ["string", "null"] }, "bsuid": { "type": ["string", "null"] }, "name": { "type": ["string", "null"] } }
      },
      "Contact": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": ["string", "null"] },
          "phone": { "type": ["string", "null"], "description": "E.164" },
          "bsuid": { "type": ["string", "null"], "description": "WhatsApp's business-scoped user ID, for a person known by username only" },
          "username": { "type": ["string", "null"] },
          "attributes": { "type": "object", "additionalProperties": { "type": ["string", "number"] }, "description": "Custom fields by field key" },
          "source": { "type": "string", "enum": ["manual", "import", "inbound", "api", "phone_app"] },
          "consent": {
            "type": "object",
            "properties": {
              "marketing": { "$ref": "#/components/schemas/ConsentState" },
              "utility": { "$ref": "#/components/schemas/ConsentState" },
              "marketing_opted_out_at": { "type": ["string", "null"], "format": "date-time" }
            }
          },
          "us_number": { "type": "boolean", "description": "A +1 number: Meta delivers no marketing to it" },
          "unreachable_until": { "type": ["string", "null"], "format": "date-time", "description": "The number was not on WhatsApp at the last try; marketing skips it until then (30 days)" },
          "last_message_at": { "type": ["string", "null"], "format": "date-time", "description": "The person's last message to you" },
          "tags": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "name": { "type": "string" } } } },
          "lists": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "name": { "type": "string" } } } },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "ContactResult": { "type": "object", "properties": { "contact": { "$ref": "#/components/schemas/Contact" } } },
      "ConsentGrant": {
        "type": "object",
        "additionalProperties": false,
        "required": ["purpose", "collected_via", "statement", "captured_at"],
        "properties": {
          "purpose": { "type": "string", "enum": ["marketing", "utility"] },
          "collected_via": { "$ref": "#/components/schemas/CollectedVia" },
          "statement": { "type": "string", "minLength": 1, "maxLength": 1000, "description": "The words the person agreed to" },
          "captured_at": { "type": "string", "format": "date-time", "description": "When they agreed, ISO 8601 with its offset" },
          "ip": { "type": "string", "description": "The IPv4 or IPv6 address they agreed from, when you have it" },
          "note": { "type": "string", "maxLength": 500 }
        }
      },
      "ConsentChange": {
        "type": "object",
        "additionalProperties": false,
        "required": ["purpose", "action"],
        "description": "A grant needs collected_via, statement and captured_at. A withdrawal needs none of them; captured_at defaults to now.",
        "properties": {
          "purpose": { "type": "string", "enum": ["marketing", "utility"] },
          "action": { "type": "string", "enum": ["grant", "withdraw"] },
          "collected_via": { "$ref": "#/components/schemas/CollectedVia" },
          "statement": { "type": "string", "minLength": 1, "maxLength": 1000 },
          "captured_at": { "type": "string", "format": "date-time" },
          "ip": { "type": "string" },
          "note": { "type": "string", "maxLength": 500 }
        }
      },
      "ConsentRecord": {
        "type": "object",
        "description": "One row of the consent ledger. Rows are never changed or deleted; a withdrawal is a new row.",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "purpose": { "type": "string", "enum": ["marketing", "utility"] },
          "action": { "type": "string", "enum": ["grant", "withdraw"] },
          "source": { "type": "string", "description": "api for a record made with a key" },
          "collected_via": { "oneOf": [{ "$ref": "#/components/schemas/CollectedVia" }, { "type": "null" }] },
          "captured_at": { "type": "string", "format": "date-time" },
          "recorded_at": { "type": "string", "format": "date-time" }
        }
      },
      "UpsertContact": {
        "type": "object",
        "additionalProperties": false,
        "description": "Give phone or bsuid (or both).",
        "properties": {
          "phone": { "type": "string", "pattern": "^\\+[1-9]\\d{6,14}$", "description": "E.164, such as +919829012345" },
          "bsuid": { "type": "string", "pattern": "^[A-Z]{2}\\.[A-Za-z0-9]{1,128}$", "description": "WhatsApp's business-scoped user ID" },
          "name": { "type": ["string", "null"], "minLength": 1, "maxLength": 120 },
          "username": { "type": ["string", "null"], "minLength": 1, "maxLength": 40 },
          "attributes": { "type": "object", "propertyNames": { "pattern": "^[a-z][a-z0-9_]{0,39}$" }, "additionalProperties": { "type": ["string", "number", "null"], "maxLength": 500 }, "description": "Custom field values by field key; null clears one" },
          "tag_ids": { "type": "array", "maxItems": 50, "items": { "type": "string", "format": "uuid" } },
          "list_ids": { "type": "array", "maxItems": 50, "items": { "type": "string", "format": "uuid" } },
          "consent": { "type": "array", "maxItems": 2, "items": { "$ref": "#/components/schemas/ConsentGrant" }, "description": "At most one grant for each purpose" }
        }
      },
      "UpsertContactResult": {
        "type": "object",
        "properties": {
          "created": { "type": "boolean" },
          "contact": { "$ref": "#/components/schemas/Contact" },
          "consent_records": { "type": "array", "items": { "$ref": "#/components/schemas/ConsentRecord" } }
        }
      },
      "UpdateContact": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "phone": { "type": ["string", "null"], "pattern": "^\\+[1-9]\\d{6,14}$" },
          "bsuid": { "type": ["string", "null"], "pattern": "^[A-Z]{2}\\.[A-Za-z0-9]{1,128}$" },
          "name": { "type": ["string", "null"], "minLength": 1, "maxLength": 120 },
          "username": { "type": ["string", "null"], "minLength": 1, "maxLength": 40 },
          "attributes": { "type": "object", "propertyNames": { "pattern": "^[a-z][a-z0-9_]{0,39}$" }, "additionalProperties": { "type": ["string", "number", "null"], "maxLength": 500 } },
          "tag_ids": { "type": "array", "maxItems": 50, "items": { "type": "string", "format": "uuid" } },
          "list_ids": { "type": "array", "maxItems": 50, "items": { "type": "string", "format": "uuid" } }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "language": { "type": "string" },
          "category": { "type": "string", "enum": ["marketing", "utility", "authentication"], "description": "Meta's category now, or the one asked for before Meta decides" },
          "status": { "type": "string", "description": "draft, check_failed, submitting, pending, approved, rejected, in_appeal, flagged, paused, disabled, archived or pending_deletion" },
          "quality": { "type": ["string", "null"], "enum": ["green", "yellow", "red", "unknown", null] },
          "sendable": { "type": "boolean", "description": "Approved, so POST /v1/messages can send it: Utility and Authentication with messages:send, Marketing with messages:send_marketing too" },
          "variables": { "type": "array", "items": { "type": "string" }, "description": "The body variables to fill; code for Authentication" },
          "header": { "type": ["object", "null"], "properties": { "format": { "type": "string", "enum": ["text", "image", "video", "document", "gif"] }, "text": { "type": ["string", "null"] } } },
          "body": { "type": ["string", "null"] },
          "footer": { "type": ["string", "null"] },
          "buttons": { "type": "array", "items": { "type": "object", "properties": { "type": { "type": "string" }, "text": { "type": ["string", "null"] } } } },
          "rejected_reason": { "type": ["string", "null"] },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "TemplateStatus": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "language": { "type": "string" },
          "status": { "type": "string" },
          "category": { "type": "string", "enum": ["marketing", "utility", "authentication"] },
          "requested_category": { "type": "string", "enum": ["marketing", "utility", "authentication"] },
          "quality": { "type": ["string", "null"] },
          "rejected_reason": { "type": ["string", "null"] },
          "paused_until": { "type": ["string", "null"], "format": "date-time" },
          "last_meta_event_at": { "type": ["string", "null"], "format": "date-time" }
        },
        "example": {"id": "0193a1b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "name": "diwali_offer", "language": "en", "status": "approved", "category": "marketing", "requested_category": "marketing", "quality": "green", "rejected_reason": null, "paused_until": null, "last_meta_event_at": "2026-11-21T08:00:00.000Z"}
      },
      "CampaignStatus": { "type": "string", "enum": ["draft", "held", "scheduled", "preparing", "sending", "paused", "paused_no_credit", "cancelling", "cancelled", "completed", "failed"] },
      "VariableMapping": {
        "type": "object",
        "additionalProperties": false,
        "required": ["source"],
        "description": "Where a template variable's value comes from. A recipient whose variable stays empty is skipped (missing_variables), never sent a broken message.",
        "properties": {
          "source": { "type": "string", "enum": ["name", "phone", "field", "text"] },
          "field": { "type": "string", "description": "The custom field key, for source field" },
          "fallback": { "type": "string", "maxLength": 200, "description": "Used when the contact has no value; the text itself for source text" }
        }
      },
      "CreateCampaign": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "audience"],
        "description": "Give template_id or template { name, language }, one of them.",
        "properties": {
          "name": { "type": "string", "minLength": 1, "maxLength": 100 },
          "template_id": { "type": "string", "format": "uuid" },
          "template": { "type": "object", "additionalProperties": false, "required": ["name", "language"], "properties": { "name": { "type": "string", "pattern": "^[a-z0-9_]{1,512}$" }, "language": { "type": "string", "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$" } } },
          "from": { "type": "string", "pattern": "^\\d{5,25}$", "description": "Meta's phone number ID of the sending number; the template's account's first number when left out" },
          "audience": {
            "type": "object",
            "additionalProperties": false,
            "description": "At least one list, segment or tag",
            "properties": {
              "list_ids": { "type": "array", "maxItems": 20, "items": { "type": "string", "format": "uuid" } },
              "segment_ids": { "type": "array", "maxItems": 20, "items": { "type": "string", "format": "uuid" } },
              "tag_ids": { "type": "array", "maxItems": 20, "items": { "type": "string", "format": "uuid" } }
            }
          },
          "variables": { "type": "object", "propertyNames": { "pattern": "^[a-z_0-9]{1,40}$" }, "additionalProperties": { "$ref": "#/components/schemas/VariableMapping" }, "description": "Each variable the template needs (variables_needed), and button_<i> for a URL or copy-code button" },
          "header_media": { "type": "object", "additionalProperties": false, "required": ["link"], "properties": { "link": { "type": "string", "maxLength": 2048, "description": "https; WhatsApp fetches it" }, "file_name": { "type": "string", "maxLength": 240, "description": "For a document header" } } }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "status": { "$ref": "#/components/schemas/CampaignStatus" },
          "template": { "type": ["object", "null"], "properties": { "id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "language": { "type": "string" }, "category": { "type": "string" }, "status": { "type": "string" } } },
          "number": { "type": ["object", "null"], "description": "The sending number: Baatzo's id for it and how it is written", "properties": { "id": { "type": "string" }, "display_phone": { "type": "string" } } },
          "category": { "type": ["string", "null"] },
          "audience": { "type": "object", "properties": { "list_ids": { "type": "array", "items": { "type": "string" } }, "segment_ids": { "type": "array", "items": { "type": "string" } }, "tag_ids": { "type": "array", "items": { "type": "string" } } } },
          "variables": { "type": "object", "additionalProperties": { "$ref": "#/components/schemas/VariableMapping" } },
          "scheduled_at": { "type": ["string", "null"], "format": "date-time" },
          "held_until": { "type": ["string", "null"], "format": "date-time", "description": "A send now waits until then; cancel stops it" },
          "recipients": { "type": ["integer", "null"], "description": "Confirmed recipients, once scheduled or sent" },
          "baatzo_fee_per_message_paise": { "type": ["string", "null"] },
          "credit": { "type": "object", "properties": { "reserved_paise": { "type": "string" }, "settled_paise": { "type": "string" }, "released_paise": { "type": "string" }, "held_paise": { "type": "string" } } },
          "pause": { "type": ["object", "null"], "properties": { "reason": { "type": "string" }, "text": { "type": ["string", "null"] } } },
          "failure_reason": { "type": ["string", "null"] },
          "started_at": { "type": ["string", "null"], "format": "date-time" },
          "completed_at": { "type": ["string", "null"], "format": "date-time" },
          "cancelled_at": { "type": ["string", "null"], "format": "date-time" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "CampaignResult": { "type": "object", "properties": { "campaign": { "$ref": "#/components/schemas/Campaign" } } },
      "CampaignStats": {
        "type": "object",
        "properties": {
          "recipients": { "type": "integer" },
          "queued": { "type": "integer" },
          "sent": { "type": "integer" },
          "delivered": { "type": "integer" },
          "read": { "type": "integer" },
          "replied": { "type": "integer" },
          "held": { "type": "integer" },
          "failed": { "type": "integer" },
          "withheld": { "type": "integer" },
          "skipped": { "type": "integer" },
          "cancelled": { "type": "integer" },
          "skipped_by_reason": { "type": "object", "additionalProperties": { "type": "integer" } },
          "failed_by_reason": { "type": "object", "additionalProperties": { "type": "integer" } },
          "baatzo_fee_paise": { "type": "string" },
          "meta_charge_estimate": { "type": "object", "properties": { "amount_micro_rupees": { "type": "string" }, "is_estimate": { "const": true } } }
        }
      },
      "CampaignEstimate": {
        "type": "object",
        "description": "Money is a string: Baatzo's fee in paise, Meta's charge in micro-rupees (an estimate, at most: Meta charges only delivered messages and adds its own GST).",
        "properties": {
          "category": { "type": "string" },
          "audience": { "type": "integer" },
          "unique": { "type": "integer" },
          "excluded": { "type": "object", "properties": { "duplicates": { "type": "integer" }, "no_identity": { "type": "integer" }, "opted_out": { "type": "integer" }, "no_consent": { "type": "integer" }, "us_number": { "type": "integer" }, "unreachable": { "type": "integer" }, "missing_variables": { "type": "integer" } } },
          "eligible": { "type": "integer" },
          "meta": { "type": "object", "properties": { "lines": { "type": "array", "items": { "type": "object", "properties": { "country": { "type": "string" }, "count": { "type": "integer" }, "rate_micro": { "type": "string" }, "total_micro": { "type": "string" } } } }, "unknown": { "type": "object", "properties": { "count": { "type": "integer" }, "countries": { "type": "array", "items": { "type": "string" } } } }, "at_most_micro": { "type": "string" } } },
          "baatzo": { "type": "object", "properties": { "fee_per_message_paise": { "type": "string" }, "fee_paise": { "type": "string" }, "gst_paise": { "type": "string" }, "total_paise": { "type": "string" }, "gst_percent": { "type": "string" } } },
          "limit": { "type": "object", "description": "Meta's messaging limit forecast", "properties": { "tier": { "type": ["string", "null"] }, "limit": { "type": ["integer", "null"] }, "used_last24h": { "type": "integer" }, "go_now": { "type": "integer" }, "later": { "type": "integer" }, "later_from": { "type": ["string", "null"] }, "expected_finish_at": { "type": "string" } } },
          "quiet_hours": { "type": ["object", "null"], "description": "The workspace's sending hours for marketing, India time", "properties": { "start": { "type": "integer" }, "end": { "type": "integer" }, "first_send_at": { "type": ["string", "null"] } } },
          "credit": { "type": "object", "properties": { "available_paise": { "type": "string" }, "needed_paise": { "type": "string" }, "enough": { "type": "boolean" }, "covered_count": { "type": "integer" } } },
          "estimated_at": { "type": "string", "format": "date-time" }
        }
      },
      "EventType": {
        "type": "string",
        "enum": ["message.sent", "message.delivered", "message.read", "message.failed", "message.received", "contact.opted_in", "contact.opted_out", "template.status_changed", "campaign.finished", "payment_link.paid", "conversation.assigned"],
        "description": "The four message.* statuses work on every paid plan; the others need a plan with the full API (Pro)."
      },
      "WebhookEndpoint": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "url": { "type": "string" },
          "status": { "type": "string", "enum": ["ACTIVE", "DISABLED"] },
          "events": { "type": "array", "items": { "$ref": "#/components/schemas/EventType" } },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "previous_secret_expires_at": { "type": ["string", "null"], "format": "date-time", "description": "During a secret rotation the old secret also signs until then" },
          "failing": { "type": "boolean" }
        }
      },
      "WebhookEndpointResult": {
        "type": "object",
        "properties": {
          "endpoint": { "oneOf": [{ "$ref": "#/components/schemas/WebhookEndpoint" }, { "type": "null" }] },
          "events": {
            "type": "object",
            "properties": {
              "full_api": { "type": "boolean", "description": "The plan has the full API" },
              "upgrade_to": { "type": ["string", "null"] },
              "types": { "type": "array", "items": { "type": "object", "properties": { "type": { "$ref": "#/components/schemas/EventType" }, "label": { "type": "string" }, "full_api": { "type": "boolean" }, "available": { "type": "boolean" } } } }
            }
          }
        }
      },
      "DeliveryStatus": { "type": "string", "enum": ["PENDING", "RETRYING", "DELIVERED", "FAILED"] },
      "Delivery": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "event_id": { "type": "string", "description": "evt_..., the id in the payload" },
          "event_type": { "type": "string" },
          "status": { "$ref": "#/components/schemas/DeliveryStatus" },
          "attempts": { "type": "integer" },
          "last_status_code": { "type": ["integer", "null"] },
          "last_latency_ms": { "type": ["integer", "null"] },
          "last_error": { "type": ["string", "null"] },
          "first_attempt_at": { "type": ["string", "null"], "format": "date-time" },
          "next_attempt_at": { "type": ["string", "null"], "format": "date-time" },
          "delivered_at": { "type": ["string", "null"], "format": "date-time" },
          "created_at": { "type": "string", "format": "date-time" },
          "replay_of": { "type": ["string", "null"], "format": "uuid" },
          "message_id": { "type": ["string", "null"] },
          "wamid": { "type": ["string", "null"] },
          "sandbox": { "type": "boolean" }
        }
      },
      "EventEnvelope": {
        "type": "object",
        "required": ["id", "type", "created_at", "data"],
        "properties": {
          "id": { "type": "string", "description": "evt_..., the same on every retry and replay of this event" },
          "type": { "$ref": "#/components/schemas/EventType" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "MessageReceivedEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "message.received" }, "data": { "type": "object", "properties": {
          "message_id": { "type": "string", "format": "uuid" },
          "wamid": { "type": "string" },
          "conversation_id": { "type": "string", "format": "uuid" },
          "phone_number_id": { "type": "string", "description": "Meta's phone number ID of the number that received it (as `from` in POST /v1/messages)" },
          "contact": { "$ref": "#/components/schemas/ContactRef" },
          "type": { "type": "string", "description": "WhatsApp's message type, such as text, image or button" },
          "text": { "type": ["string", "null"], "description": "The text, or a media caption" },
          "reply_to_wamid": { "type": ["string", "null"] },
          "received_at": { "type": "string", "format": "date-time" } } } } }],
        "example": {"id": "evt_0193c2a0-1b2c-7d3e-8f4a-5b6c7d8e9f01", "type": "message.received", "created_at": "2026-11-28T10:05:00.000Z", "data": {"message_id": "0193c2a0-1b2c-7d3e-8f4a-5b6c7d8e9f00", "wamid": "wamid.HBgMOTE5ODI5MDEyMzQ1FQIAEhgg", "conversation_id": "0193b9e0-1111-7222-8333-444455556666", "phone_number_id": "109876543210987", "contact": {"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma"}, "type": "text", "text": "Is the offer on till Sunday?", "reply_to_wamid": null, "received_at": "2026-11-28T10:04:59.000Z"}}
      },
      "ContactOptedInEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "contact.opted_in" }, "data": { "type": "object", "properties": { "contact": { "$ref": "#/components/schemas/ContactRef" }, "purpose": { "type": "string", "enum": ["marketing", "utility"] } } } } }],
        "example": {"id": "evt_0193c2a1-0000-7000-8000-000000000001", "type": "contact.opted_in", "created_at": "2026-11-28T10:00:01.000Z", "data": {"contact": {"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma"}, "purpose": "marketing"}}
      },
      "ContactOptedOutEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "contact.opted_out" }, "data": { "type": "object", "properties": { "contact": { "$ref": "#/components/schemas/ContactRef" }, "purpose": { "type": "string", "enum": ["marketing", "utility"] }, "opted_out_at": { "type": ["string", "null"], "format": "date-time" } } } } }],
        "example": {"id": "evt_0193c2a2-0000-7000-8000-000000000002", "type": "contact.opted_out", "created_at": "2026-11-28T12:00:00.000Z", "data": {"contact": {"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma"}, "purpose": "marketing", "opted_out_at": "2026-11-28T11:59:58.000Z"}}
      },
      "TemplateStatusChangedEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "template.status_changed" }, "data": { "type": "object", "properties": { "template_id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "language": { "type": "string" }, "category": { "type": "string" }, "previous_status": { "type": "string" }, "status": { "type": "string" }, "reason": { "type": ["string", "null"] } } } } }],
        "example": {"id": "evt_0193c2a3-0000-7000-8000-000000000003", "type": "template.status_changed", "created_at": "2026-11-21T08:00:01.000Z", "data": {"template_id": "0193a1b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "name": "diwali_offer", "language": "en", "category": "marketing", "previous_status": "pending", "status": "approved", "reason": null}}
      },
      "CampaignFinishedEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "campaign.finished" }, "data": { "type": "object", "properties": { "campaign_id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "status": { "type": "string", "enum": ["completed", "cancelled", "failed"] }, "failure_reason": { "type": ["string", "null"] }, "finished_at": { "type": "string", "format": "date-time" }, "stats": { "$ref": "#/components/schemas/CampaignStats" } } } } }],
        "example": {"id": "evt_0193c2a4-0000-7000-8000-000000000004", "type": "campaign.finished", "created_at": "2026-12-05T11:20:00.000Z", "data": {"campaign_id": "0193c0d1-2e3f-7a4b-8c5d-6e7f8a9b0c1d", "name": "Diwali offer 2026", "status": "completed", "failure_reason": null, "finished_at": "2026-12-05T11:20:00.000Z", "stats": {"recipients": 1200, "queued": 0, "sent": 1180, "delivered": 1150, "read": 900, "replied": 64, "held": 0, "failed": 20, "withheld": 0, "skipped": 0, "cancelled": 0, "skipped_by_reason": {}, "failed_by_reason": {"131026": 20}, "baatzo_fee_paise": "5750", "meta_charge_estimate": {"amount_micro_rupees": "992565000", "is_estimate": true}}}}
      },
      "PaymentLinkPaidEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "payment_link.paid" }, "data": { "type": "object", "properties": { "payment_link_id": { "type": "string", "format": "uuid" }, "reference_id": { "type": ["string", "null"] }, "description": { "type": ["string", "null"] }, "amount_paise": { "type": "string" }, "paid_amount_paise": { "type": "string" }, "method": { "type": ["string", "null"] }, "razorpay_payment_id": { "type": ["string", "null"] }, "contact": { "$ref": "#/components/schemas/ContactRef" }, "conversation_id": { "type": ["string", "null"] }, "paid_at": { "type": "string", "format": "date-time" } } } } }],
        "example": {"id": "evt_0193c2a5-0000-7000-8000-000000000005", "type": "payment_link.paid", "created_at": "2026-11-28T13:00:00.000Z", "data": {"payment_link_id": "0193c2a5-0000-7000-8000-0000000000aa", "reference_id": "order-1042", "description": "Order 1042", "amount_paise": "149900", "paid_amount_paise": "149900", "method": "upi", "razorpay_payment_id": "pay_PQ1234567890ab", "contact": {"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma"}, "conversation_id": "0193b9e0-1111-7222-8333-444455556666", "paid_at": "2026-11-28T12:59:58.000Z"}}
      },
      "ConversationAssignedEvent": {
        "allOf": [{ "$ref": "#/components/schemas/EventEnvelope" }, { "type": "object", "properties": { "type": { "const": "conversation.assigned" }, "data": { "type": "object", "properties": { "conversation_id": { "type": "string", "format": "uuid" }, "contact": { "$ref": "#/components/schemas/ContactRef" }, "assignee": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "name": { "type": ["string", "null"] } } }, "method": { "type": "string", "enum": ["manual", "automation", "round_robin"] }, "assigned_at": { "type": "string", "format": "date-time" } } } } }],
        "example": {"id": "evt_0193c2a6-0000-7000-8000-000000000006", "type": "conversation.assigned", "created_at": "2026-11-28T10:06:00.000Z", "data": {"conversation_id": "0193b9e0-1111-7222-8333-444455556666", "contact": {"id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma"}, "assignee": {"id": "0193a000-aaaa-7bbb-8ccc-dddddddddddd", "name": "Ravi"}, "method": "round_robin", "assigned_at": "2026-11-28T10:06:00.000Z"}}
      },
      "Export": {
        "type": "object",
        "required": ["id", "status", "everything", "created_at", "download_url"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "status": { "type": "string", "enum": ["queued", "building", "ready", "failed"] },
          "everything": { "type": "boolean" },
          "contacts": { "type": ["integer", "null"], "description": "Contacts in the file, once built" },
          "created_at": { "type": "string", "format": "date-time" },
          "completed_at": { "type": ["string", "null"], "format": "date-time" },
          "expires_at": { "type": ["string", "null"], "format": "date-time", "description": "Downloadable until then (7 days)" },
          "download_url": { "type": ["string", "null"], "description": "A path on this host while the export can be downloaded" },
          "failure_reason": { "type": ["string", "null"] }
        }
      }
    }
  }
}
