{
  "openapi": "3.0.3",
  "info": {
    "title": "Routa API",
    "description": "REST API to send and receive WhatsApp messages, track delivery and receive normalized events through webhooks.",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://api.routa.chat",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Send, retrieve and list messages."
    },
    {
      "name": "Events",
      "description": "Query the log of normalized events."
    },
    {
      "name": "Webhooks",
      "description": "Manage webhook endpoints, secrets and deliveries."
    },
    {
      "name": "Templates",
      "description": "Create and retrieve WhatsApp templates."
    },
    {
      "name": "Media",
      "description": "Upload and download media files."
    },
    {
      "name": "Usage",
      "description": "Query the metered usage of the project."
    },
    {
      "name": "Identity",
      "description": "Identify the API key in use."
    },
    {
      "name": "Partners",
      "description": "Create one project per customer, issue the key of each project, follow the channels and receive the events of every customer on a single webhook. These routes use a partner key (`rt_partner_...`). See [Partner API](/en/partners/overview)."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/messages": {
      "post": {
        "operationId": "sendMessage",
        "tags": [
          "Messages"
        ],
        "summary": "Send message",
        "description": "Sends a text or template message through a channel.\n\nThe response is `202 Accepted`: the message is durably stored, but **not delivered yet**. Follow `sent`, `delivered`, `read` and `failed` through [webhooks](/en/webhooks/overview) or `GET /v1/messages/{id}`.\n\nProvide `text` or `template`. With neither, the API returns `content_rejected`. With both, it sends the template and ignores `text`. Send the `Idempotency-Key` header to retry the request safely. See [Idempotency](/en/reliability/idempotency).\n\nA template send carries exactly what the template asks for: one value in `body_parameters` for each body variable, `header_parameter` when the header is text with a variable or is media, and one item in `button_parameters` for each URL button with a variable. A missing, extra, mismatched or empty parameter returns `422 content_rejected`, and so does a value that WhatsApp refuses. See [Header and buttons](/en/guides/send-template-message#header-and-buttons).\n\nThe channel, the recipient, the template and the header file are validated when the message is accepted, so the error comes back right away. A refused request stores no message and uses none of your allowance. An imported, read-only template returns `template_not_sendable`.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A unique key per logical message (a UUID v4, for example). Repeating the request with the same key and the same body returns the original response, with the `Idempotent-Replay: true` header. A key reused with a different body returns `409 idempotency_key_reuse`. The record is kept for 24 hours.",
            "schema": {
              "type": "string"
            },
            "example": "6f0a9d9e-3c1f-4e56-9a64-2b7f6a5c1d10"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "channel",
                  "to"
                ],
                "properties": {
                  "channel": {
                    "description": "ID of the channel to send through (`chan_...`).",
                    "type": "string",
                    "example": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
                  },
                  "to": {
                    "pattern": "^\\+?[1-9]\\d{1,14}$",
                    "description": "Recipient in E.164 format, for example `+5581999999999`. The leading `+` is optional. A value outside this format returns `request_invalid`; a number that cannot exist in its country returns `invalid_recipient`.",
                    "type": "string",
                    "example": "+5581999999999"
                  },
                  "text": {
                    "description": "Body of the text message, up to 4096 characters. It is ignored when the request also carries `template`.",
                    "type": "string",
                    "example": "Hi! Your order is confirmed."
                  },
                  "template": {
                    "type": "object",
                    "required": [
                      "id"
                    ],
                    "properties": {
                      "id": {
                        "description": "Template ID (`tmpl_...`). The template must be `approved`.",
                        "type": "string",
                        "example": "tmpl_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
                      },
                      "body_parameters": {
                        "description": "Positional values for the `{{1}}`, `{{2}}`, … placeholders of the template body, in order. The count must match the number of variables in the template. A value cannot hold a line break, a tab or 5 spaces in a row.",
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "header_parameter": {
                        "description": "The value of the template header. Send `text` when the text header has a variable, or `media_id` when the header is media, on **every** send. Omit it when the header asks for nothing: there is no header, or its text is fixed.",
                        "type": "object",
                        "properties": {
                          "text": {
                            "description": "The value of the header variable. Text headers only. It cannot hold a line break, a tab or 5 spaces in a row.",
                            "type": "string"
                          },
                          "media_id": {
                            "description": "The file of the media header: the `id` (`med_...`) returned by `POST /v1/media`, of a type the header format accepts (`image`: JPEG or PNG; `video`: MP4; `document`: PDF). A file received from a contact is refused. Media headers only.",
                            "type": "string"
                          },
                          "filename": {
                            "description": "The file name the recipient sees. Optional, and for document headers only.",
                            "type": "string"
                          }
                        }
                      },
                      "button_parameters": {
                        "description": "One item for each URL button whose URL has a variable. Other buttons take no item.",
                        "type": "array",
                        "items": {
                          "type": "object",
                          "required": [
                            "index",
                            "text"
                          ],
                          "properties": {
                            "index": {
                              "description": "The position of the button in `components.buttons`, as returned by `GET /v1/templates/{id}`, starting at 0. Every button counts, of any kind.",
                              "type": "integer",
                              "example": 0
                            },
                            "text": {
                              "description": "The value that replaces `{{1}}` in the button URL. Routa passes it on exactly as it arrives, so percent-encode it first: spaces, line breaks, accented letters, emoji and any other character outside visible ASCII are refused.",
                              "type": "string",
                              "example": "1234"
                            }
                          }
                        }
                      }
                    },
                    "description": "Approved template to send, instead of `text`."
                  },
                  "metadata": {
                    "maxProperties": 20,
                    "description": "Up to 20 text key-value pairs that you own, 1 KB in total. Returned when you retrieve the message and in its events.",
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    }
                  }
                }
              },
              "example": {
                "channel": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
                "to": "+5581999999999",
                "text": "Hi! Your order is confirmed.",
                "metadata": {
                  "order_id": "1234"
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted. Processing is asynchronous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Plan allowance or limit used up (`message_quota_exceeded`, `free_messages_exhausted`, `subscription_required`, `payment_failed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project (`channel_not_found`, `template_not_found`, `media_not_found`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency or state conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `channel_inactive`, `capability_unsupported`, `invalid_recipient`, `content_rejected`, `template_not_approved`, `template_paused`, `template_not_sendable`, `media_not_ready`, `media_content_type_rejected`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "messages:write"
            ]
          }
        ],
        "x-required-scope": "messages:write"
      },
      "get": {
        "operationId": "listMessages",
        "tags": [
          "Messages"
        ],
        "summary": "List messages",
        "description": "Lists the messages of the project, newest first, with cursor pagination. Filter by `direction` to see only inbound or only outbound messages.\n\nOn a number connected in coexistence mode, the list includes the messages the business sent from the WhatsApp Business app (`origin: business_app`) and the imported history. A message whose content is older than your plan retains comes with `content: null` and `content_redacted_at`.",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "enum": [
                "inbound",
                "outbound"
              ]
            },
            "in": "query",
            "name": "direction",
            "required": false,
            "description": "Filters by message direction: `inbound` (received) or `outbound` (sent)."
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "in": "query",
            "name": "limit",
            "required": false,
            "description": "Number of items per page, from 1 to 100. The default is 20."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "cursor",
            "required": false,
            "description": "The `next_cursor` value of the previous page. Treat it as opaque."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageList"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "messages:read"
            ]
          }
        ],
        "x-required-scope": "messages:read"
      }
    },
    "/v1/messages/{id}": {
      "get": {
        "operationId": "retrieveMessage",
        "tags": [
          "Messages"
        ],
        "summary": "Retrieve message",
        "description": "Returns a message with its current status and the time of each step (`sent_at`, `delivered_at`, `read_at`, `failed_at`).",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Message ID (`msg_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "messages:read"
            ]
          }
        ],
        "x-required-scope": "messages:read"
      }
    },
    "/v1/messages/{id}/read": {
      "post": {
        "operationId": "markMessageAsRead",
        "tags": [
          "Messages"
        ],
        "summary": "Mark message as read",
        "description": "Marks an **inbound** message as read and sends the read receipt to its sender. For a message you sent, it returns `422` with the `message_direction_invalid` code.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "ID of the inbound message (`msg_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "messages:write"
            ]
          }
        ],
        "x-required-scope": "messages:write"
      }
    },
    "/v1/events": {
      "get": {
        "operationId": "listEvents",
        "tags": [
          "Events"
        ],
        "summary": "List events",
        "description": "Lists the events of the project in ascending `sequence` order, oldest first. This is the **reconciliation** path when you miss webhook deliveries: store the `id` of the last event you processed and pass it in `after`.\n\nEvents are available for 90 days. See [Reconcile events](/en/webhooks/reconciliation).\n\nEach event carries the `external_ref` of the project, which is `null` when the project has none.",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "enum": [
                "message.accepted",
                "message.sent",
                "message.delivered",
                "message.read",
                "message.failed",
                "message.received",
                "channel.status_changed",
                "template.submitted",
                "template.pending",
                "template.approved",
                "template.rejected",
                "template.paused",
                "template.disabled",
                "template.failed",
                "template.category_changed",
                "template.updated",
                "template.deleted"
              ]
            },
            "in": "query",
            "name": "type",
            "required": false,
            "description": "Filters by event type, for example `message.delivered` or `template.deleted`."
          },
          {
            "description": "Resumes the listing after this event ID (`evt_...`).",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "after",
            "required": false
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "in": "query",
            "name": "limit",
            "required": false,
            "description": "Number of items per page, from 1 to 100. The default is 20."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventList"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "events:read"
            ]
          }
        ],
        "x-required-scope": "events:read"
      }
    },
    "/v1/webhook_endpoints": {
      "post": {
        "operationId": "createWebhookEndpoint",
        "tags": [
          "Webhooks"
        ],
        "summary": "Create webhook endpoint",
        "description": "Registers a URL to receive events. The response includes the signing `secret`, **shown only once**. Store it to [verify signatures](/en/webhooks/signatures).\n\nThe URL must use HTTPS and cannot point to private addresses. `http://localhost` is accepted only in test projects. Each project can have up to 5 endpoints.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "subscribed_types"
                ],
                "properties": {
                  "url": {
                    "description": "HTTPS URL that receives the events. `http://` is accepted only for localhost in test projects.",
                    "type": "string",
                    "example": "https://example.com/webhooks/routa"
                  },
                  "subscribed_types": {
                    "minItems": 1,
                    "description": "Event types or per-resource wildcards (`message.*`, `channel.*`, `template.*`). At least one.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "message.*",
                      "channel.status_changed"
                    ]
                  }
                }
              },
              "example": {
                "url": "https://example.com/webhooks/routa",
                "subscribed_types": [
                  "message.*",
                  "channel.status_changed"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Resource created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      },
      "get": {
        "operationId": "listWebhookEndpoints",
        "tags": [
          "Webhooks"
        ],
        "summary": "List webhook endpoints",
        "description": "Lists the webhook endpoints of the project (5 at most). Listings never return the `secret`.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointList"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}": {
      "get": {
        "operationId": "retrieveWebhookEndpoint",
        "tags": [
          "Webhooks"
        ],
        "summary": "Retrieve webhook endpoint",
        "description": "Returns an endpoint, including `status`, `consecutive_failures` and the times of the last success and the last failure.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      },
      "patch": {
        "operationId": "updateWebhookEndpoint",
        "tags": [
          "Webhooks"
        ],
        "summary": "Update subscribed types",
        "description": "Replaces the list of event types the endpoint subscribes to. The list cannot be empty and accepts wildcards such as `message.*`.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "subscribed_types"
                ],
                "properties": {
                  "subscribed_types": {
                    "minItems": 1,
                    "description": "New list of types or wildcards. It replaces the current list.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "message.delivered",
                      "message.failed"
                    ]
                  }
                }
              },
              "example": {
                "subscribed_types": [
                  "message.delivered",
                  "message.failed"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}/rotate_secret": {
      "post": {
        "operationId": "rotateWebhookEndpointSecret",
        "tags": [
          "Webhooks"
        ],
        "summary": "Rotate secret",
        "description": "Generates a new signing secret and returns it. The previous secret stays valid for **24 hours**, and during that time deliveries are signed with both. See [Verify signatures](/en/webhooks/signatures).",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}/disable": {
      "post": {
        "operationId": "disableWebhookEndpoint",
        "tags": [
          "Webhooks"
        ],
        "summary": "Disable endpoint",
        "description": "Pauses deliveries to the endpoint (`status: disabled_by_user`). Events are still recorded in the log.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}/enable": {
      "post": {
        "operationId": "enableWebhookEndpoint",
        "tags": [
          "Webhooks"
        ],
        "summary": "Re-enable endpoint",
        "description": "Re-enables a disabled endpoint and **replays every exhausted delivery in a batch**. The response reports how many were replayed in `replayed_count`.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Endpoint ID."
                    },
                    "url": {
                      "type": "string",
                      "description": "URL that receives the events."
                    },
                    "subscribed_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Subscribed event types, including wildcards such as `message.*`."
                    },
                    "api_version": {
                      "type": "string",
                      "description": "API version pinned when the endpoint was created."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "enabled",
                        "disabled_by_user",
                        "disabled_by_system"
                      ],
                      "description": "Endpoint state: `enabled`, `disabled_by_user` or `disabled_by_system`."
                    },
                    "consecutive_failures": {
                      "type": "number",
                      "description": "Consecutive delivery failures. Resets on every success."
                    },
                    "last_success_at": {
                      "format": "date-time",
                      "type": "string",
                      "nullable": true,
                      "description": "Last successful delivery, or `null`."
                    },
                    "last_failure_at": {
                      "format": "date-time",
                      "type": "string",
                      "nullable": true,
                      "description": "Last failed delivery, or `null`."
                    },
                    "created_at": {
                      "format": "date-time",
                      "type": "string",
                      "description": "When the endpoint was created."
                    },
                    "replayed_count": {
                      "type": "number",
                      "description": "Number of exhausted deliveries replayed when the endpoint was re-enabled."
                    }
                  },
                  "required": [
                    "id",
                    "url",
                    "subscribed_types",
                    "api_version",
                    "status",
                    "consecutive_failures",
                    "last_success_at",
                    "last_failure_at",
                    "created_at",
                    "replayed_count"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}/deliveries": {
      "get": {
        "operationId": "listWebhookDeliveries",
        "tags": [
          "Webhooks"
        ],
        "summary": "List deliveries",
        "description": "Lists the deliveries of an endpoint, newest first. Filter by `state=exhausted` to see the deliveries that ran out of attempts. Deliveries can be queried for 30 days.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "in_flight",
                "retrying",
                "succeeded",
                "exhausted"
              ]
            },
            "in": "query",
            "name": "state",
            "required": false,
            "description": "Filters by delivery state."
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "in": "query",
            "name": "limit",
            "required": false,
            "description": "Number of items per page, from 1 to 100. The default is 20."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "cursor",
            "required": false,
            "description": "The `next_cursor` value of the previous page. Treat it as opaque."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDeliveryList"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}/deliveries/{deliveryId}/replay": {
      "post": {
        "operationId": "replayWebhookDelivery",
        "tags": [
          "Webhooks"
        ],
        "summary": "Replay a delivery",
        "description": "Replays a delivery in the `exhausted` state. A delivery in any other state returns `409` with the `webhook_delivery_not_replayable` code.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "deliveryId",
            "required": true,
            "description": "Delivery ID (`whd_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReplayResult"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency or state conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/webhook_endpoints/{id}/deliveries/replay": {
      "post": {
        "operationId": "replayWebhookDeliveries",
        "tags": [
          "Webhooks"
        ],
        "summary": "Replay all exhausted deliveries",
        "description": "Replays every exhausted delivery of the endpoint at once. Returns how many were replayed.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Endpoint ID (`whe_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReplayResult"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/templates": {
      "post": {
        "operationId": "createTemplate",
        "tags": [
          "Templates"
        ],
        "summary": "Create template",
        "description": "Creates a template and sends it to WhatsApp for approval. The provider decides on approval, in its own time. Follow it through the `template.*` events or by retrieving the template.\n\nOnly `approved` templates can be used in `POST /v1/messages`. See [Templates](/en/concepts/templates).\n\n**Every variable needs an example**, which WhatsApp reads when it reviews the template: `variable_examples` for the body, `components.header.example` for the variable of a text header and `components.buttons[].example` for each URL button with a variable (only the value that replaces `{{1}}`). No recipient receives the examples, but they are stored, returned by the API and sent in events and webhooks: **do not use real personal data or tokens**.\n\nRouta refuses **right away**, with `422`, what WhatsApp is already known to refuse. The error then points at the right field, instead of leaving you with a `failed` template minutes later. The `error.param` field says which part of the request failed.\n\n| Rule | Error and `error.param` |\n| --- | --- |\n| The name uses only `a-z`, `0-9` and `_`, up to 512 characters | `template_name_invalid`, `name` |\n| The body has up to 1024 characters | `template_components_invalid`, `body_text` |\n| Variables are numbered in sequence starting at `{{1}}` | `template_variables_invalid` |\n| The body does not start or end with a `{{n}}` variable | `template_variables_invalid` |\n| The text header has up to 60 characters and one variable | `template_components_invalid`, `components.header` |\n| The footer has up to 60 characters | `template_components_invalid`, `components.footer` |\n| At most 10 buttons, 1 phone button and 2 URL buttons | `template_components_invalid`, `components.buttons` |\n| Quick reply buttons stay together, with no other button between them | `template_components_invalid`, `components.buttons` |\n| Button text has up to 25 characters, the URL up to 2000 and the phone number up to 20 | `template_components_invalid`, `components.buttons` |\n| The `{{1}}` variable of a URL goes at its end, and the URL does not point to `api.whatsapp.com` | `template_components_invalid`, `components.buttons` |\n| An `authentication` template takes no buttons of its own | `template_components_invalid`, `components.buttons` |\n| Every body variable has an example | `template_variables_invalid`, `variable_examples` or `variable_examples.<position>` |\n| The header variable and the variable of each URL button have an example, and whatever has no variable takes no example | `template_variables_invalid`, `components.header.example` or `components.buttons.<position>.example` |\n\nWhatsApp decides on approval. A rule Routa does not check can still lead to `rejected` or `failed`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "channel",
                  "name",
                  "language",
                  "category",
                  "body_text"
                ],
                "properties": {
                  "channel": {
                    "description": "Channel the template belongs to (`chan_...`).",
                    "type": "string",
                    "example": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
                  },
                  "name": {
                    "description": "Template name: only lowercase letters, digits and `_` (`a-z`, `0-9`, `_`), up to 512 characters.",
                    "type": "string",
                    "example": "order_confirmation"
                  },
                  "language": {
                    "description": "The language of the template, in the code WhatsApp uses, such as `pt_BR`, `en_US` or `en`. The region is joined with an underscore (`en_US`, not `en-US`).",
                    "type": "string",
                    "example": "en_US"
                  },
                  "category": {
                    "type": "string",
                    "enum": [
                      "marketing",
                      "utility",
                      "authentication"
                    ],
                    "description": "Template category: `marketing`, `utility` or `authentication`."
                  },
                  "body_text": {
                    "description": "Template body, with positional placeholders `{{1}}`, `{{2}}`, …, up to 1024 characters. It cannot start or end with a variable.",
                    "type": "string",
                    "example": "Hi {{1}}! Your order {{2}} is confirmed."
                  },
                  "variable_examples": {
                    "description": "One example for each variable of `body_text`, the first one for `{{1}}`: the order of the numbers counts, not the order in the text. **Required when the body has a variable**, with exactly one item per variable, none empty or blank. Do not use real personal data or tokens.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "Ana",
                      "1234"
                    ]
                  },
                  "components": {
                    "description": "Optional components: a text or media header, a footer and up to 10 buttons. Omit the field for a text-only template.",
                    "type": "object",
                    "properties": {
                      "header": {
                        "oneOf": [
                          {
                            "type": "object",
                            "required": [
                              "kind",
                              "text"
                            ],
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "text"
                                ],
                                "description": "Use `text` for a text header."
                              },
                              "text": {
                                "description": "Header text, up to 60 characters and at most one `{{1}}` variable.",
                                "type": "string"
                              },
                              "example": {
                                "description": "Example of the header `{{1}}`. **Required when the text has the variable**. Refused when it does not, and when empty or blank.",
                                "type": "string"
                              }
                            }
                          },
                          {
                            "type": "object",
                            "required": [
                              "kind",
                              "media_id"
                            ],
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "media"
                                ],
                                "description": "Use `media` for a media header."
                              },
                              "media_id": {
                                "description": "ID (`tmedia_...`) of the file uploaded beforehand with `POST /v1/templates/media`.",
                                "type": "string"
                              },
                              "example": {
                                "description": "Refused here: a media header has no variable (`422 template_variables_invalid`).",
                                "type": "string"
                              }
                            }
                          }
                        ],
                        "description": "Text header (up to 60 characters and one variable) or media header (a `media_id` from `POST /v1/templates/media`)."
                      },
                      "footer": {
                        "type": "object",
                        "required": [
                          "text"
                        ],
                        "properties": {
                          "text": {
                            "description": "Footer text, up to 60 characters.",
                            "type": "string"
                          }
                        },
                        "description": "Text footer, up to 60 characters."
                      },
                      "buttons": {
                        "description": "Up to 10 buttons: at most 1 `phone_number` and 2 `url`. The `quick_reply` buttons stay together, before or after the others. Each button text has up to 25 characters. The URL of a `url` button has up to 2000 characters and can have one `{{1}}` variable, only at the end of the URL.",
                        "type": "array",
                        "items": {
                          "oneOf": [
                            {
                              "type": "object",
                              "required": [
                                "kind",
                                "text"
                              ],
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "quick_reply"
                                  ],
                                  "description": "Use `quick_reply` for a quick reply button."
                                },
                                "text": {
                                  "description": "Button text, up to 25 characters.",
                                  "type": "string"
                                },
                                "example": {
                                  "description": "Refused here: this button has no variable (`422 template_variables_invalid`).",
                                  "type": "string"
                                }
                              }
                            },
                            {
                              "type": "object",
                              "required": [
                                "kind",
                                "text",
                                "phone_number"
                              ],
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "phone_number"
                                  ],
                                  "description": "Use `phone_number` for a button that calls a number."
                                },
                                "text": {
                                  "description": "Button text, up to 25 characters.",
                                  "type": "string"
                                },
                                "phone_number": {
                                  "description": "The number the button calls, up to 20 characters.",
                                  "type": "string"
                                },
                                "example": {
                                  "description": "Refused here: this button has no variable (`422 template_variables_invalid`).",
                                  "type": "string"
                                }
                              }
                            },
                            {
                              "type": "object",
                              "required": [
                                "kind",
                                "text",
                                "url"
                              ],
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "url"
                                  ],
                                  "description": "Use `url` for a button that opens an address."
                                },
                                "text": {
                                  "description": "Button text, up to 25 characters.",
                                  "type": "string"
                                },
                                "url": {
                                  "description": "Destination URL. It can have a single `{{1}}` variable, at the end.",
                                  "type": "string"
                                },
                                "example": {
                                  "description": "Example of what replaces `{{1}}`: **only that value**, not the whole URL. **Required when the URL has the variable**. Refused when it does not, and when empty or blank.",
                                  "type": "string"
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "channel": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
                "name": "order_confirmation",
                "language": "en_US",
                "category": "utility",
                "body_text": "Hi {{1}}! Your order {{2}} is confirmed.",
                "variable_examples": [
                  "Ana",
                  "1234"
                ],
                "components": {
                  "buttons": [
                    {
                      "kind": "url",
                      "text": "Track order",
                      "url": "https://example.com/orders/{{1}}",
                      "example": "1234"
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Resource created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Template"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project (`channel_not_found`, `template_media_not_found`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `capability_unsupported`, `template_name_invalid`, `template_variables_invalid`, `template_components_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "templates:write"
            ]
          }
        ],
        "x-required-scope": "templates:write",
        "x-codeSamples": [
          {
            "lang": "bash",
            "label": "cURL",
            "source": "curl --request POST https://api.routa.chat/v1/templates \\\n  --header \"Authorization: Bearer $ROUTA_API_KEY\" \\\n  --header \"Content-Type: application/json\" \\\n  --data '{\n  \"channel\": \"chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ\",\n  \"name\": \"order_confirmation\",\n  \"language\": \"en_US\",\n  \"category\": \"utility\",\n  \"body_text\": \"Hi {{1}}! Your order {{2}} is confirmed.\",\n  \"variable_examples\": [\n    \"Ana\",\n    \"1234\"\n  ],\n  \"components\": {\n    \"buttons\": [\n      {\n        \"kind\": \"url\",\n        \"text\": \"Track order\",\n        \"url\": \"https://example.com/orders/{{1}}\",\n        \"example\": \"1234\"\n      }\n    ]\n  }\n}'"
          },
          {
            "lang": "typescript",
            "label": "Node.js",
            "source": "import { Routa } from '@routa-chat/sdk'\n\nconst routa = new Routa({ apiKey: process.env['ROUTA_API_KEY']! })\n\nconst template = await routa.templates.submit({\n  channel: 'chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ',\n  name: 'order_confirmation',\n  language: 'en_US',\n  category: 'utility',\n  bodyText: 'Hi {{1}}! Your order {{2}} is confirmed.',\n  variableExamples: ['Ana', '1234'],\n  components: {\n    buttons: [\n      { kind: 'url', text: 'Track order', url: 'https://example.com/orders/{{1}}', example: '1234' },\n    ],\n  },\n})"
          }
        ]
      },
      "get": {
        "operationId": "listTemplates",
        "tags": [
          "Templates"
        ],
        "summary": "List templates",
        "description": "Lists the templates of the project with cursor pagination. Filter by channel with `channel`. The list includes templates imported from WhatsApp (`origin: provider`), including read-only ones (`read_only: true`), which cannot be used to send. You edit and delete a template in the dashboard.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "channel",
            "required": false,
            "description": "Filters by channel ID (`chan_...`)."
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "in": "query",
            "name": "limit",
            "required": false,
            "description": "Number of items per page, from 1 to 100. The default is 20."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "cursor",
            "required": false,
            "description": "The `next_cursor` value of the previous page. Treat it as opaque."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateList"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "templates:read"
            ]
          }
        ],
        "x-required-scope": "templates:read"
      }
    },
    "/v1/templates/{id}": {
      "get": {
        "operationId": "retrieveTemplate",
        "tags": [
          "Templates"
        ],
        "summary": "Retrieve template",
        "description": "Returns a template with its current approval `status`. If it was rejected, `rejection_reason` gives the reason. If Routa could not send it to WhatsApp (`status: failed`), `failure_code` gives the reason and `failure_detail` carries the provider's own sentence, when it gave one. Through the API, you have to create the template again. In the dashboard, a `failed` or `rejected` template can be edited and sent again.\n\nWhile a deletion requested in the dashboard is in progress, `deletion_requested` is `true` and the template cannot be used to send.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Template ID (`tmpl_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Template"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "templates:read"
            ]
          }
        ],
        "x-required-scope": "templates:read"
      }
    },
    "/v1/templates/media": {
      "post": {
        "operationId": "uploadTemplateMedia",
        "tags": [
          "Templates"
        ],
        "summary": "Upload header media",
        "description": "Uploads an image, a video or a document to use as a template header. Send the file bytes **directly in the body**, with the `Content-Type` of the file. The format is inferred from the type.\n\n| Format | Accepted types | Maximum size |\n| --- | --- | --- |\n| `image` | `image/jpeg`, `image/png` | 5 MB |\n| `video` | `video/mp4` | 16 MB |\n| `document` | `application/pdf` | 100 MB |\n\nUse the returned `id` in `components.header.media_id` when you create the template.\n\nThis file is the sample WhatsApp reviews. It is not reused when you send: each message carries its own file, uploaded with [`POST /v1/media`](/en/api-reference/endpoint/media/upload).",
        "requestBody": {
          "required": true,
          "description": "The file bytes, with the `Content-Type` of the file (for example `image/png`).",
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Resource created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateMedia"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "templates:write"
            ]
          }
        ],
        "x-required-scope": "templates:write"
      }
    },
    "/v1/media": {
      "post": {
        "operationId": "uploadMedia",
        "tags": [
          "Media"
        ],
        "summary": "Upload or host media",
        "description": "Stores a media file in Routa's custody. There are two ways, chosen by the `Content-Type`:\n\n- **Bytes:** send the file in the body, with the `Content-Type` of the file.\n- **URL:** send `application/json` with `{ \"source_url\": \"https://...\" }` and Routa downloads the file. The URL must be public.\n\nAccepted types and sizes follow the WhatsApp limits. See [Media](/en/concepts/media).\n\nThe returned `id` is what you pass in `template.header_parameter.media_id` to send a template with a media header.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "source_url"
                ],
                "properties": {
                  "source_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Public URL of the file Routa should download.",
                    "example": "https://example.com/image.png"
                  }
                }
              }
            },
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary",
                "description": "The file bytes. Use the real `Content-Type` of the file, for example `image/jpeg`."
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Resource created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Media"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "media:write"
            ]
          }
        ],
        "x-required-scope": "media:write"
      }
    },
    "/v1/media/{id}": {
      "get": {
        "operationId": "retrieveMedia",
        "tags": [
          "Media"
        ],
        "summary": "Retrieve media",
        "description": "Returns the media object with a **fresh signed URL**, valid for 15 minutes, when `status` is `ready`. If it is `pending`, retrieve it again in a moment.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "Media ID (`med_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Media"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist or belongs to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "media:read"
            ]
          }
        ],
        "x-required-scope": "media:read"
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "retrieveUsage",
        "tags": [
          "Usage"
        ],
        "summary": "Retrieve usage",
        "description": "Returns the metered usage of the project over a period, with one row per combination of metric, channel type and provider. The current day, still open, is read live. The range spans 92 days at most.",
        "parameters": [
          {
            "description": "Start date in UTC, in `YYYY-MM-DD` format, inclusive.",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "from",
            "required": true
          },
          {
            "description": "End date in UTC, in `YYYY-MM-DD` format, exclusive. The range spans 92 days at most.",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "to",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": [
              "usage:read"
            ]
          }
        ],
        "x-required-scope": "usage:read"
      }
    },
    "/v1/whoami": {
      "get": {
        "operationId": "whoami",
        "tags": [
          "Identity"
        ],
        "summary": "Identify the API key",
        "description": "Resolves the API key in use to its organization, project and scopes. It has no side effects and accepts any valid key, which makes it ideal for checking a key.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Whoami"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, invalid, revoked or expired (`api_key_invalid`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/partner/projects": {
      "post": {
        "operationId": "createPartnerProject",
        "tags": [
          "Partners"
        ],
        "summary": "Create a customer project",
        "description": "Creates the project of one of your customers. Use **one project per customer**.\n\nThe `external_ref` is **your** ID for the customer. It is unique in the organization and never changes. Repeating the call with the same `external_ref` does not create a second project: the API returns the existing one with `200`, and the `name` you send is ignored. The first call returns `201`.\n\nCreating the project is optional: a customer's first [signed link](/en/partners/signed-link) also creates it. The project is always created as live (`environment: live`).\n\nYour plan limits the number of projects. When you reach the limit, the API returns `402 project_limit_exceeded`. Deleting the project of a customer who left frees the slot.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "external_ref"
                ],
                "properties": {
                  "name": {
                    "description": "Project name, from 1 to 200 characters. The customer sees it on the connection page. It is a display name, not an identity.",
                    "type": "string",
                    "example": "Acme Store"
                  },
                  "external_ref": {
                    "description": "Your ID for the customer: 1 to 128 characters among `A-Z`, `a-z`, `0-9`, `.`, `_`, `:` and `-`. Never use an email address, phone number or name. It is unique in the organization and set once.",
                    "type": "string",
                    "example": "lead_123"
                  }
                }
              },
              "example": {
                "name": "Acme Store",
                "external_ref": "lead_123"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A project with this `external_ref` already existed. It is returned unchanged",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProject"
                }
              }
            }
          },
          "201": {
            "description": "Project created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProject"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Your plan's project limit is reached (`project_limit_exceeded`, with `error.details.limit`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `invalid_project_name`, `invalid_external_ref`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "projects:write"
            ]
          }
        ],
        "x-required-scope": "projects:write"
      },
      "get": {
        "operationId": "listPartnerProjects",
        "tags": [
          "Partners"
        ],
        "summary": "List projects",
        "description": "Lists the projects created through the Partner API, with cursor pagination. Projects your team created in the dashboard do not appear.\n\nFilter by `external_ref` to find a customer's project, or by `has_channel` to separate those who already connected a number from those who have not.",
        "parameters": [
          {
            "description": "Returns only the project with this `external_ref`. An empty page when no project has it.",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "external_ref",
            "required": false
          },
          {
            "description": "Use `false` for projects with no channel at all and `true` for those with at least one, in any state. A project that only has disabled channels is **not** a project without a channel. Any other value returns `422`.",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "in": "query",
            "name": "has_channel",
            "required": false
          },
          {
            "description": "Number of items per page, from 1 to 200. The default is 50.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "in": "query",
            "name": "limit",
            "required": false
          },
          {
            "description": "The `next_cursor` value of the previous page. Treat it as opaque.",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "cursor",
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProjectList"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `invalid_cursor`, `invalid_external_ref`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "projects:read"
            ]
          }
        ],
        "x-required-scope": "projects:read"
      }
    },
    "/v1/partner/projects/{projectId}": {
      "get": {
        "operationId": "retrievePartnerProject",
        "tags": [
          "Partners"
        ],
        "summary": "Retrieve project",
        "description": "Returns the project with its `external_ref` and its channels (`id` and `status`).\n\nIt is **this** request, and not the redirect of the signed link, that confirms a connection. The redirect is only a hint: anyone can forge a request to your `redirect_url`. See the [onboarding guide](/en/partners/onboarding).",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProjectDetail"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "projects:read"
            ]
          }
        ],
        "x-required-scope": "projects:read"
      },
      "patch": {
        "operationId": "updatePartnerProject",
        "tags": [
          "Partners"
        ],
        "summary": "Rename project",
        "description": "Renames the project. The `external_ref` **cannot change**: sending its current value is accepted, and any other value returns `422 external_ref_immutable`.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "description": "New display name, from 1 to 200 characters.",
                    "type": "string",
                    "example": "Acme Store Ltd"
                  },
                  "external_ref": {
                    "description": "Accepted only to be refused. Send the current value or omit the field.",
                    "type": "string"
                  }
                }
              },
              "example": {
                "name": "Acme Store Ltd"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProject"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `invalid_project_name`, `external_ref_immutable`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "projects:write"
            ]
          }
        ],
        "x-required-scope": "projects:write"
      },
      "delete": {
        "operationId": "deletePartnerProject",
        "tags": [
          "Partners"
        ],
        "summary": "Delete project",
        "description": "Deletes a customer's project and everything in it, to free its slot in your plan's project limit. An abandoned link or a customer who left keeps counting until you delete the project.\n\nRequires the `projects:delete` scope, which a new key does **not** have. Only a project created through the Partner API is accepted.\n\nThe API deletes the project's messages, templates, events, contacts, keys, webhook endpoints, media files and **disabled** channels. The numbers of those channels become free. The plan, the allowance, the audit log and the partner keys of the organization do not change. Nothing changes on WhatsApp.\n\nThe project cannot be deleted while it still has a channel that is not disabled (`has_enabled_channel`) or when it is the last project of the organization (`last_project`). In both cases the response is `409 project_not_deletable`.\n\nThe response is `204` once the project is gone. On a large project, a call can delete only part of it and return `202` with `status: deleting`. The project is still there, partly deleted. **Repeat the same call until you get `204`.**",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          }
        ],
        "responses": {
          "202": {
            "description": "The deletion is not finished yet. Repeat the call until you get `204`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProjectDeleting"
                }
              }
            }
          },
          "204": {
            "description": "The project is deleted"
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The project cannot be deleted (`project_not_deletable`). `error.details.reason` is `has_enabled_channel` or `last_project`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "projects:delete"
            ]
          }
        ],
        "x-required-scope": "projects:delete"
      }
    },
    "/v1/partner/projects/{projectId}/api_keys": {
      "post": {
        "operationId": "createPartnerProjectApiKey",
        "tags": [
          "Partners"
        ],
        "summary": "Issue project API key",
        "description": "Issues the API key of a project. **This** key, not the partner key, is what the customer's traffic uses on `/v1/messages`, `/v1/templates` and the other routes. The partner key never sends messages.\n\nThe `secret` is shown **only once**, in the response. Store it safely.\n\nRequires the `api_keys:write` scope, which a new partner key does **not** have. A leaked partner key with this scope can issue keys that send messages for any of your customers. Restrict it to the addresses of your servers and set an expiry.\n\nAsk for the smallest set of scopes that works. The scopes of a project key are listed in [Authentication](/en/authentication). Unknown values are ignored, and `scopes: []` creates a key that cannot do anything.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "scopes"
                ],
                "properties": {
                  "name": {
                    "description": "What you call this key, for example `Backend of customer 123`. At most 80 characters, after trimming the surrounding spaces.",
                    "type": "string",
                    "example": "Acme Store"
                  },
                  "scopes": {
                    "description": "Scopes of the project key. Ask only for the ones you need.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "messages:write",
                      "messages:read"
                    ]
                  },
                  "expires_at": {
                    "format": "date-time",
                    "type": "string",
                    "description": "When the key expires, in ISO 8601. Without this field, the key does not expire."
                  },
                  "ip_allowlist": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "IPv4 addresses or IPv4 CIDR blocks allowed to use the key. IPv6 addresses are compared as exact text. An empty list applies no restriction."
                  }
                }
              },
              "example": {
                "name": "Acme Store",
                "scopes": [
                  "messages:write",
                  "messages:read"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Key created. The `secret` is shown only once",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProjectApiKeyWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `invalid_api_key_name`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "api_keys:write"
            ]
          }
        ],
        "x-required-scope": "api_keys:write"
      }
    },
    "/v1/partner/projects/{projectId}/api_keys/{id}/rotate": {
      "post": {
        "operationId": "rotatePartnerProjectApiKey",
        "tags": [
          "Partners"
        ],
        "summary": "Rotate project API key",
        "description": "Creates a replacement for the given key. The original key **stays active** until you revoke it, so you can swap the key in your system without interrupting sends. The response carries the `secret` of the new key, shown only once.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "ID of the project API key (`key_...`)."
          }
        ],
        "responses": {
          "201": {
            "description": "New key created. The `secret` is shown only once",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProjectApiKeyWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "api_keys:write"
            ]
          }
        ],
        "x-required-scope": "api_keys:write"
      }
    },
    "/v1/partner/projects/{projectId}/api_keys/{id}/revoke": {
      "post": {
        "operationId": "revokePartnerProjectApiKey",
        "tags": [
          "Partners"
        ],
        "summary": "Revoke project API key",
        "description": "Revokes the key. It stops working immediately. Use it after you [rotate](/en/api-reference/endpoint/partner/rotate-project-api-key) a key, or when a customer leaves.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "id",
            "required": true,
            "description": "ID of the project API key (`key_...`)."
          }
        ],
        "responses": {
          "200": {
            "description": "Key revoked. `revoked_at` says when",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerProjectApiKey"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "api_keys:write"
            ]
          }
        ],
        "x-required-scope": "api_keys:write"
      }
    },
    "/v1/partner/channels": {
      "get": {
        "operationId": "listPartnerChannels",
        "tags": [
          "Partners"
        ],
        "summary": "List customer channels",
        "description": "Lists, in one call, the channels of all your customers, in any state (`pending`, `active`, `degraded` and `disabled`). Each channel carries the `external_ref` of its project.\n\nA `disabled` channel keeps the project from being deleted and still holds the number. To free the number, [delete the channel](/en/api-reference/endpoint/partner/delete-channel).\n\nThe item carries no credentials and no provider data.",
        "parameters": [
          {
            "description": "Returns only the channels in this state: `pending`, `active`, `degraded` or `disabled`. Any other value returns `422`.",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "active",
                "degraded",
                "disabled"
              ]
            },
            "in": "query",
            "name": "status",
            "required": false
          },
          {
            "description": "Returns only the channels of this project (`proj_...`). An empty page when the organization does not have the project.",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "in": "query",
            "name": "project_id",
            "required": false
          },
          {
            "description": "Returns only the channels of the project with this `external_ref`. An empty page when no project has it.",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "external_ref",
            "required": false
          },
          {
            "description": "Number of items per page, from 1 to 200. The default is 50.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "in": "query",
            "name": "limit",
            "required": false
          },
          {
            "description": "The `next_cursor` value of the previous page. Treat it as opaque.",
            "schema": {
              "type": "string"
            },
            "in": "query",
            "name": "cursor",
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PartnerChannelList"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid` for an unknown `status`, `invalid_cursor`, `invalid_external_ref`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "projects:read"
            ]
          }
        ],
        "x-required-scope": "projects:read"
      }
    },
    "/v1/partner/projects/{projectId}/channels/{channelId}": {
      "delete": {
        "operationId": "deletePartnerChannel",
        "tags": [
          "Partners"
        ],
        "summary": "Delete disabled channel",
        "description": "Deletes a **disabled** channel of one of your projects, to free the number so the customer can connect it again.\n\nRequires the `channels:write` scope, which a new partner key does **not** have. A channel in any other state returns `409 channel_not_disabled`.\n\nThe API deletes the channel, its credential and its templates. Messages, usage and events keep referring to the channel. Nothing changes on WhatsApp.",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "projectId",
            "required": true,
            "description": "Project ID (`proj_...`). Only a project created through the Partner API is accepted."
          },
          {
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "channelId",
            "required": true,
            "description": "Channel ID (`chan_...`)."
          }
        ],
        "responses": {
          "204": {
            "description": "The channel is deleted"
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The channel is not disabled (`channel_not_disabled`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "channels:write"
            ]
          }
        ],
        "x-required-scope": "channels:write"
      }
    },
    "/v1/partner/webhook": {
      "get": {
        "operationId": "retrievePartnerWebhook",
        "tags": [
          "Partners"
        ],
        "summary": "Retrieve organization webhook",
        "description": "Returns the single webhook endpoint of the organization, with `status`, `consecutive_failures` and the times of the last success and the last failure. The secret is never returned.\n\nThere is no read-only scope: this route uses `webhooks:write`.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The organization has not set up the webhook yet (`webhook_endpoint_not_found`), or the plan does not include the Partner API (`partner_api_not_available`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      },
      "put": {
        "operationId": "setPartnerWebhook",
        "tags": [
          "Partners"
        ],
        "summary": "Set organization webhook",
        "description": "Sets the **only** webhook endpoint of the organization, which receives the events of **all** your customers. Each event carries the `project_id` and the `external_ref` of the project, so you route by your own ID without keeping a lookup table.\n\nThe first call creates the endpoint and returns `201` with the signing `secret`, **shown only once**. Later calls (`200`) replace the URL and the subscribed types, re-enable the endpoint and do not return the secret.\n\nSignatures and attempts follow the rules of a project's [webhooks](/en/webhooks/overview). You can also keep endpoints on individual projects: in that case, you receive both deliveries.\n\nAn endpoint that carries many customers is the bottleneck of all of them. It has at most 32 concurrent deliveries (8 on a project endpoint), so answer fast and queue the work on your side. See [Organization webhook](/en/partners/webhook).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "subscribed_types"
                ],
                "properties": {
                  "url": {
                    "description": "HTTPS URL that receives the events of every project in the organization. The address must resolve to a public host.",
                    "type": "string",
                    "example": "https://crm.example.com/routa"
                  },
                  "subscribed_types": {
                    "minItems": 1,
                    "description": "Event types or per-resource wildcards (`message.*`, `channel.*`, `template.*`). At least one. The bare `*` wildcard is not accepted.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "message.*",
                      "channel.status_changed"
                    ]
                  }
                }
              },
              "example": {
                "url": "https://crm.example.com/routa",
                "subscribed_types": [
                  "message.*",
                  "channel.status_changed"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Endpoint updated and re-enabled. The response does not include the secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "201": {
            "description": "Endpoint created. The `secret` is shown only once",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The resource does not exist, does not belong to your organization or was not created through the Partner API. Also returns `partner_api_not_available` when your plan does not include the Partner API",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request (`request_invalid`, `invalid_webhook_url`, `invalid_subscribed_types`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    },
    "/v1/partner/webhook/rotate_secret": {
      "post": {
        "operationId": "rotatePartnerWebhookSecret",
        "tags": [
          "Partners"
        ],
        "summary": "Rotate webhook secret",
        "description": "Generates a new signing secret and returns it, **only once**. The previous secret keeps signing deliveries for **24 hours**, so you can swap the secret in your system without losing events. See [Verify signatures](/en/webhooks/signatures).",
        "responses": {
          "201": {
            "description": "New secret generated. It is shown only once",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpointWithSecret"
                }
              }
            }
          },
          "401": {
            "description": "The partner key is missing, invalid, revoked, expired or used from outside its IP allowlist (`partner_key_invalid`). A project key also gets this error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The partner key lacks the required scope (`insufficient_scope`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The organization has not set up the webhook yet (`webhook_endpoint_not_found`), or the plan does not include the Partner API (`partner_api_not_available`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded: 10 requests per second, with bursts of up to 30, per organization. See the `Retry-After` header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "partnerAuth": [
              "webhooks:write"
            ]
          }
        ],
        "x-required-scope": "webhooks:write"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Project API key, in the format `rt_live_...` or `rt_test_...`, sent as `Authorization: Bearer <key>`."
      },
      "partnerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Partner key, in the format `rt_partner_...`, sent as `Authorization: Bearer <key>`. It only works on the `/v1/partner/*` routes. A project key does not work on them, and a partner key does not work on any other route."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "type",
              "code",
              "message",
              "request_id"
            ],
            "properties": {
              "type": {
                "type": "string",
                "description": "Error category: `invalid_request_error`, `authentication_error`, `permission_error`, `not_found_error`, `conflict_error`, `rate_limit_error`, `billing_error` or `api_error`.",
                "example": "invalid_request_error"
              },
              "code": {
                "type": "string",
                "description": "Stable, machine-readable code. See [Error codes](/en/errors/error-codes).",
                "example": "channel_inactive"
              },
              "message": {
                "type": "string",
                "description": "Human-readable text, in English. It can change, so do not parse it.",
                "example": "Channel chan_01J8... is not active and cannot send messages."
              },
              "param": {
                "type": "string",
                "description": "The request field at fault, when it applies. It is filled in on `request_invalid` (the field outside the schema, such as `template.button_parameters.0.index`) and on template errors: `name` in `template_name_invalid`; `body_text`, `components.header`, `components.footer` or `components.buttons` in `template_components_invalid`; and `variable_examples`, `variable_examples.<position>`, `components.header.example` or `components.buttons.<position>.example` when `template_variables_invalid` refuses an example.",
                "example": "components.buttons.0.example"
              },
              "doc_url": {
                "type": "string",
                "description": "Link to the documentation of the code, when available."
              },
              "details": {
                "type": "object",
                "additionalProperties": {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "number"
                    }
                  ]
                },
                "description": "Actionable values, such as `limit`, `used` and `resets_at` in `message_quota_exceeded`, or `reason`, which tells apart the causes behind one code, in errors such as `invalid_recipient` and `template_variables_invalid`. See [Actionable details](/en/errors/overview#actionable-details)."
              },
              "request_id": {
                "type": "string",
                "description": "Request ID. Quote it when you contact support.",
                "example": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
              }
            },
            "description": "Error details."
          }
        },
        "required": [
          "error"
        ]
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Message ID.",
            "example": "msg_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "channel": {
            "type": "string",
            "description": "ID of the channel used.",
            "example": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "direction": {
            "type": "string",
            "enum": [
              "outbound",
              "inbound"
            ],
            "description": "Message direction: `outbound` (left the channel's number, through the API or the WhatsApp Business app) or `inbound` (received)."
          },
          "origin": {
            "type": "string",
            "enum": [
              "api",
              "business_app"
            ],
            "nullable": true,
            "description": "Where an `outbound` message came from: `api` (sent through Routa) or `business_app` (the business sent it from the WhatsApp Business app, on a number connected in coexistence mode). A `business_app` message is not billed and does not count as usage. It is `null` on an `inbound` message.",
            "example": "api"
          },
          "from": {
            "type": "string",
            "description": "Sender address, in E.164.",
            "example": "+5581988888888"
          },
          "to": {
            "type": "string",
            "description": "Recipient address, in E.164. On a `business_app` message, it can be a provider identifier when the recipient's number is unknown.",
            "example": "+5581999999999"
          },
          "content": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "type",
                  "body"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "text"
                    ],
                    "description": "Always `text` on a text message."
                  },
                  "body": {
                    "type": "string",
                    "description": "Body of the text."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "media_id"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "image"
                    ],
                    "description": "Always `image` on an image."
                  },
                  "media_id": {
                    "type": "string",
                    "description": "ID (`med_...`) of the file stored by Routa. Call `GET /v1/media/{id}` to get a signed URL."
                  },
                  "caption": {
                    "type": "string",
                    "description": "Caption. Absent when there is none."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "media_id"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "document"
                    ],
                    "description": "Always `document` on a document."
                  },
                  "media_id": {
                    "type": "string",
                    "description": "ID (`med_...`) of the file stored by Routa. Call `GET /v1/media/{id}` to get a signed URL."
                  },
                  "filename": {
                    "type": "string",
                    "description": "File name. Absent when there is none."
                  },
                  "caption": {
                    "type": "string",
                    "description": "Caption. Absent when there is none."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "media_id"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "audio"
                    ],
                    "description": "Always `audio` on an audio message."
                  },
                  "media_id": {
                    "type": "string",
                    "description": "ID (`med_...`) of the file stored by Routa. Call `GET /v1/media/{id}` to get a signed URL."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "media_id"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "video"
                    ],
                    "description": "Always `video` on a video."
                  },
                  "media_id": {
                    "type": "string",
                    "description": "ID (`med_...`) of the file stored by Routa. Call `GET /v1/media/{id}` to get a signed URL."
                  },
                  "caption": {
                    "type": "string",
                    "description": "Caption. Absent when there is none."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "media_id"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "sticker"
                    ],
                    "description": "Always `sticker` on a sticker."
                  },
                  "media_id": {
                    "type": "string",
                    "description": "ID (`med_...`) of the file stored by Routa. Call `GET /v1/media/{id}` to get a signed URL."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "latitude",
                  "longitude"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "location"
                    ],
                    "description": "Always `location` on a location."
                  },
                  "latitude": {
                    "type": "number",
                    "description": "Latitude of the place."
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude of the place."
                  },
                  "name": {
                    "type": "string",
                    "description": "Name of the place. Absent when there is none."
                  },
                  "address": {
                    "type": "string",
                    "description": "Address of the place. Absent when there is none."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "target_message_id",
                  "emoji"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "reaction"
                    ],
                    "description": "Always `reaction` on a reaction."
                  },
                  "target_message_id": {
                    "type": "string",
                    "description": "ID (`msg_...`) of the message that was reacted to."
                  },
                  "emoji": {
                    "type": "string",
                    "description": "The reaction emoji. An empty string means an earlier reaction was removed."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type",
                  "template_id",
                  "body_parameters"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "template"
                    ],
                    "description": "Always `template` on a template send."
                  },
                  "template_id": {
                    "type": "string",
                    "description": "ID (`tmpl_...`) of the template sent."
                  },
                  "body_parameters": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "The values of the `{{n}}` variables of the body, in order."
                  },
                  "header_parameter": {
                    "oneOf": [
                      {
                        "type": "object",
                        "required": [
                          "text"
                        ],
                        "properties": {
                          "text": {
                            "type": "string",
                            "description": "The value of the variable in the text header."
                          }
                        }
                      },
                      {
                        "type": "object",
                        "required": [
                          "media_id"
                        ],
                        "properties": {
                          "media_id": {
                            "type": "string",
                            "description": "ID (`med_...`) of the file sent in the media header."
                          },
                          "filename": {
                            "type": "string",
                            "description": "File name of a document header. Absent when none was given."
                          }
                        }
                      }
                    ],
                    "description": "What was sent to the template header: `text`, the value of its variable, or `media_id` (with `filename`, on a document). Absent when the header asks for nothing."
                  },
                  "button_parameters": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "index",
                        "text"
                      ],
                      "properties": {
                        "index": {
                          "type": "integer",
                          "description": "The position of the button in `components.buttons`, starting at 0."
                        },
                        "text": {
                          "type": "string",
                          "description": "The value that replaced `{{1}}` in the button URL."
                        }
                      }
                    },
                    "description": "The values sent to the URL buttons with a variable, as received. `index` is the position of the button in `components.buttons`, starting at 0. Absent when the template asks for none."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "type"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "unsupported"
                    ],
                    "description": "Always `unsupported`: received content that Routa does not represent yet."
                  }
                }
              }
            ],
            "nullable": true,
            "description": "Message content. The `type` field gives the format. It is `null` once retention removes the content; `content_redacted_at` then gives the time of the removal."
          },
          "content_redacted_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When retention removed the message content. `null` while the message still has it.",
            "example": null
          },
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "sent",
              "delivered",
              "read",
              "failed"
            ],
            "description": "Current state in the lifecycle. The status never goes back."
          },
          "failure_code": {
            "type": "string",
            "nullable": true,
            "description": "Reason for the failure, from a closed set of Routa codes, never a provider code. `null` until the message fails.",
            "example": null
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Up to 20 text key-value pairs that you own."
          },
          "accepted_at": {
            "format": "date-time",
            "type": "string",
            "description": "When Routa accepted the message.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "sent_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the provider accepted the message. `null` if it has not happened yet.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "delivered_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When delivery was confirmed. `null` if it has not happened yet.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "read_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the recipient read it. `null` if it has not happened yet.",
            "example": null
          },
          "failed_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the message failed. `null` if it did not fail.",
            "example": null
          }
        },
        "required": [
          "id",
          "channel",
          "direction",
          "origin",
          "from",
          "to",
          "content",
          "content_redacted_at",
          "status",
          "failure_code",
          "metadata",
          "accepted_at",
          "sent_at",
          "delivered_at",
          "read_at",
          "failed_at"
        ]
      },
      "MessageList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            },
            "description": "Messages on this page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more pages."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor of the next page, or `null` on the last one."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Event": {
        "type": "object",
        "required": [
          "id",
          "type",
          "api_version",
          "schema_version",
          "project_id",
          "external_ref",
          "sequence",
          "occurred_at",
          "recorded_at",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Event ID. This is the deduplication key.",
            "example": "evt_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "type": {
            "type": "string",
            "enum": [
              "message.accepted",
              "message.sent",
              "message.delivered",
              "message.read",
              "message.failed",
              "message.received",
              "channel.status_changed",
              "template.submitted",
              "template.pending",
              "template.approved",
              "template.rejected",
              "template.paused",
              "template.disabled",
              "template.failed",
              "template.category_changed",
              "template.updated",
              "template.deleted"
            ],
            "description": "Event type, in the format `resource.past_tense_action`."
          },
          "api_version": {
            "type": "string",
            "description": "Version of the public format of the resource in `data`.",
            "example": "v1"
          },
          "schema_version": {
            "type": "number",
            "description": "Version of the event envelope.",
            "example": 1
          },
          "project_id": {
            "type": "string",
            "description": "Project that owns the event.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "external_ref": {
            "type": "string",
            "nullable": true,
            "description": "The `external_ref` of the project (the customer's ID on the partner platform), or `null` on a project that has none. Set once and never changes.",
            "example": null
          },
          "sequence": {
            "type": "number",
            "description": "Monotonic number, useful to detect gaps. It is not a promise of delivery order."
          },
          "occurred_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the fact happened.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "recorded_at": {
            "format": "date-time",
            "type": "string",
            "description": "When Routa recorded the event.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "data": {
            "description": "The full resource in its current state, not a diff. For message events it is the message; for template events, the template."
          }
        }
      },
      "EventList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            },
            "description": "Events on this page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more events."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "ID of the last event on the page, or `null` on the last one. Use it in `after`."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Template ID.",
            "example": "tmpl_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "channel": {
            "type": "string",
            "description": "Channel the template belongs to.",
            "example": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "name": {
            "type": "string",
            "description": "Template name.",
            "example": "order_confirmation"
          },
          "language": {
            "type": "string",
            "description": "The WhatsApp language code, such as `pt_BR` or `en_US`.",
            "example": "en_US"
          },
          "category": {
            "type": "string",
            "enum": [
              "marketing",
              "utility",
              "authentication"
            ],
            "description": "Category: `marketing`, `utility` or `authentication`."
          },
          "body_text": {
            "type": "string",
            "nullable": true,
            "description": "The template body, with the `{{1}}`, `{{2}}`, … placeholders. It is `null` only on an imported, read-only template (`read_only`), which Routa cannot reproduce.",
            "example": "Hi {{1}}! Your order {{2}} is confirmed."
          },
          "variables": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "index"
              ],
              "properties": {
                "index": {
                  "type": "number",
                  "description": "The number of the variable, starting at 1.",
                  "example": 1
                },
                "example": {
                  "type": "string",
                  "description": "The example written for the variable. Absent when the template has none for it, such as an imported template or one created before examples were required.",
                  "example": "Ana"
                }
              }
            },
            "description": "Positional placeholders of the body (`{{1}}`, `{{2}}`, …)."
          },
          "components": {
            "type": "object",
            "properties": {
              "header": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "kind",
                      "text"
                    ],
                    "properties": {
                      "kind": {
                        "type": "string",
                        "enum": [
                          "text"
                        ],
                        "description": "Always `text` on a text header."
                      },
                      "text": {
                        "type": "string",
                        "description": "Header text."
                      },
                      "example": {
                        "type": "string",
                        "description": "The example of the header variable. Absent when there is no variable or no example."
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "kind",
                      "format",
                      "media_id"
                    ],
                    "properties": {
                      "kind": {
                        "type": "string",
                        "enum": [
                          "media"
                        ],
                        "description": "Always `media` on a media header."
                      },
                      "format": {
                        "type": "string",
                        "enum": [
                          "image",
                          "video",
                          "document"
                        ],
                        "description": "Media format: `image`, `video` or `document`."
                      },
                      "media_id": {
                        "type": "string",
                        "description": "ID (`tmedia_...`) of the header sample file."
                      }
                    }
                  }
                ],
                "description": "Template header: text (`kind: text`) or media (`kind: media`). Absent when the template has no header."
              },
              "footer": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "Footer text."
                  }
                },
                "description": "Template footer. Absent when the template has none."
              },
              "buttons": {
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "kind",
                        "text"
                      ],
                      "properties": {
                        "kind": {
                          "type": "string",
                          "enum": [
                            "quick_reply"
                          ],
                          "description": "Always `quick_reply`: a quick reply button."
                        },
                        "text": {
                          "type": "string",
                          "description": "Button text."
                        }
                      }
                    },
                    {
                      "type": "object",
                      "required": [
                        "kind",
                        "text",
                        "phone_number"
                      ],
                      "properties": {
                        "kind": {
                          "type": "string",
                          "enum": [
                            "phone_number"
                          ],
                          "description": "Always `phone_number`: a button that calls a number."
                        },
                        "text": {
                          "type": "string",
                          "description": "Button text."
                        },
                        "phone_number": {
                          "type": "string",
                          "description": "The number the button calls."
                        }
                      }
                    },
                    {
                      "type": "object",
                      "required": [
                        "kind",
                        "text",
                        "url"
                      ],
                      "properties": {
                        "kind": {
                          "type": "string",
                          "enum": [
                            "url"
                          ],
                          "description": "Always `url`: a button that opens an address."
                        },
                        "text": {
                          "type": "string",
                          "description": "Button text."
                        },
                        "url": {
                          "type": "string",
                          "description": "Address the button opens. It can have the `{{1}}` variable, at the end."
                        },
                        "example": {
                          "type": "string",
                          "description": "The example of the URL's `{{1}}`. Absent when there is no variable or no example."
                        }
                      }
                    }
                  ]
                },
                "description": "Template buttons, in order. Absent when the template has none."
              }
            },
            "description": "Header, footer and buttons of the template. The field is omitted, not empty, on a body-only template."
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "submitted",
              "pending",
              "approved",
              "rejected",
              "paused",
              "disabled",
              "failed"
            ],
            "description": "Approval state. Only `approved` allows sending. `rejected` means the provider reviewed the template and refused it. `failed` means Routa could not send it to the provider. A `failed` or `rejected` template can be edited and sent again in the dashboard, and then goes back to `submitted`."
          },
          "rejection_reason": {
            "type": "string",
            "enum": [
              "abusive_content",
              "incorrect_category",
              "invalid_format",
              "scam",
              "tag_content_mismatch",
              "other"
            ],
            "nullable": true,
            "description": "Reason for the rejection, when `status` is `rejected`."
          },
          "failure_code": {
            "type": "string",
            "enum": [
              "provider_unavailable",
              "provider_auth_failed",
              "provider_rejected_request",
              "channel_unavailable",
              "media_unavailable",
              "attempts_exhausted"
            ],
            "nullable": true,
            "description": "Why it could not be sent for approval, when `status` is `failed`. `null` in every other status.",
            "example": null
          },
          "failure_detail": {
            "type": "string",
            "nullable": true,
            "description": "Only when `status` is `failed` and the provider explained why: its own sentence, written for a person and often in the language of the account. It is informational text. Never compare against it; use `failure_code`. `null` otherwise.",
            "example": null
          },
          "deletion_requested": {
            "type": "boolean",
            "description": "`true` from the moment a deletion is accepted (made in the dashboard) until Routa finishes deleting the template on WhatsApp. In between, the template cannot be used to send, and a message that cites it returns `422 template_not_sendable`. `false` otherwise.",
            "example": false
          },
          "deletion_failure_detail": {
            "type": "string",
            "nullable": true,
            "description": "Why the last deletion ended without deleting the template, in the provider's own sentence when it gave one. It is informational text. `null` when no deletion failed.",
            "example": null
          },
          "origin": {
            "type": "string",
            "enum": [
              "routa",
              "provider"
            ],
            "description": "Who created the template: `routa` for a template created by Routa, `provider` for one that already existed on WhatsApp and was imported.",
            "example": "routa"
          },
          "read_only": {
            "type": "boolean",
            "description": "`true` for an imported template that Routa cannot reproduce. Sending a message with it returns `422 template_not_sendable`. Always `false` when `origin` is `routa`.",
            "example": false
          },
          "unsupported_components": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "named_parameters",
                "media_header",
                "location_header",
                "carousel",
                "flow_button",
                "otp_button",
                "copy_code_button",
                "catalog",
                "limited_time_offer",
                "other"
              ]
            },
            "description": "Components of an imported template that Routa cannot reproduce. Empty when `read_only` is `false`.",
            "example": []
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the template was created.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the template was last updated.",
            "example": "2026-09-04T13:22:41.031Z"
          }
        },
        "required": [
          "id",
          "channel",
          "name",
          "language",
          "category",
          "body_text",
          "variables",
          "status",
          "rejection_reason",
          "failure_code",
          "failure_detail",
          "deletion_requested",
          "deletion_failure_detail",
          "origin",
          "read_only",
          "unsupported_components",
          "created_at",
          "updated_at"
        ]
      },
      "TemplateList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Template"
            },
            "description": "Templates on this page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more pages."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor of the next page, or `null` on the last one."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "WebhookEndpoint": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Endpoint ID.",
            "example": "whe_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "url": {
            "type": "string",
            "description": "URL that receives the events.",
            "example": "https://example.com/webhooks/routa"
          },
          "subscribed_types": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Subscribed event types, including wildcards such as `message.*`."
          },
          "api_version": {
            "type": "string",
            "description": "API version pinned when the endpoint was created."
          },
          "status": {
            "type": "string",
            "enum": [
              "enabled",
              "disabled_by_user",
              "disabled_by_system"
            ],
            "description": "Endpoint state: `enabled`, `disabled_by_user` or `disabled_by_system`."
          },
          "consecutive_failures": {
            "type": "number",
            "description": "Consecutive delivery failures. Resets on every success."
          },
          "last_success_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "Last successful delivery, or `null`."
          },
          "last_failure_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "Last failed delivery, or `null`."
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the endpoint was created.",
            "example": "2026-09-04T13:22:41.031Z"
          }
        },
        "required": [
          "id",
          "url",
          "subscribed_types",
          "api_version",
          "status",
          "consecutive_failures",
          "last_success_at",
          "last_failure_at",
          "created_at"
        ]
      },
      "WebhookEndpointWithSecret": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Endpoint ID.",
            "example": "whe_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "url": {
            "type": "string",
            "description": "URL that receives the events.",
            "example": "https://example.com/webhooks/routa"
          },
          "subscribed_types": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Subscribed event types, including wildcards such as `message.*`."
          },
          "api_version": {
            "type": "string",
            "description": "API version pinned when the endpoint was created."
          },
          "status": {
            "type": "string",
            "enum": [
              "enabled",
              "disabled_by_user",
              "disabled_by_system"
            ],
            "description": "Endpoint state: `enabled`, `disabled_by_user` or `disabled_by_system`."
          },
          "consecutive_failures": {
            "type": "number",
            "description": "Consecutive delivery failures. Resets on every success."
          },
          "last_success_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "Last successful delivery, or `null`."
          },
          "last_failure_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "Last failed delivery, or `null`."
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the endpoint was created.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "secret": {
            "type": "string",
            "description": "Signing secret. Shown only on creation and rotation. Store it safely.",
            "example": "whsec_..."
          }
        },
        "required": [
          "id",
          "url",
          "subscribed_types",
          "api_version",
          "status",
          "consecutive_failures",
          "last_success_at",
          "last_failure_at",
          "created_at",
          "secret"
        ]
      },
      "WebhookEndpointList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEndpoint"
            },
            "description": "Endpoints of the project."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more pages. Always `false` today."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Always `null`. The listing returns every endpoint at once."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "WebhookDelivery": {
        "type": "object",
        "required": [
          "id",
          "event_id",
          "event_type",
          "state",
          "attempt_count",
          "next_attempt_at",
          "last_response_status",
          "last_error_code",
          "succeeded_at",
          "exhausted_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Delivery ID.",
            "example": "whd_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "event_id": {
            "type": "string",
            "description": "Event delivered.",
            "example": "evt_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "event_type": {
            "type": "string",
            "description": "Type of the event delivered.",
            "example": "message.delivered"
          },
          "state": {
            "type": "string",
            "enum": [
              "pending",
              "in_flight",
              "retrying",
              "succeeded",
              "exhausted"
            ],
            "description": "Delivery state: `pending`, `in_flight`, `retrying`, `succeeded` or `exhausted`."
          },
          "attempt_count": {
            "type": "number",
            "description": "Attempts made."
          },
          "next_attempt_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the next attempt happens."
          },
          "last_response_status": {
            "type": "number",
            "nullable": true,
            "description": "HTTP status of the last response from your server, or `null`."
          },
          "last_error_code": {
            "type": "string",
            "nullable": true,
            "description": "Code of the last error, such as a timeout or a connection failure, or `null`."
          },
          "succeeded_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the delivery succeeded, or `null`."
          },
          "exhausted_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When it ran out of attempts, or `null`."
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the delivery was created.",
            "example": "2026-09-04T13:22:41.031Z"
          }
        }
      },
      "WebhookDeliveryList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookDelivery"
            },
            "description": "Deliveries on this page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more pages."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor of the next page, or `null` on the last one."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "ReplayResult": {
        "type": "object",
        "properties": {
          "replayed_count": {
            "type": "number",
            "description": "Number of deliveries replayed.",
            "example": 12
          }
        },
        "required": [
          "replayed_count"
        ]
      },
      "Media": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Media ID.",
            "example": "med_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "content_type": {
            "type": "string",
            "description": "MIME type of the file.",
            "example": "image/jpeg"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "ready",
              "unavailable"
            ],
            "description": "State: `pending`, `ready` or `unavailable`."
          },
          "url": {
            "type": "string",
            "nullable": true,
            "description": "Signed URL, valid for 15 minutes. Present only when `status` is `ready`."
          }
        },
        "required": [
          "id",
          "content_type",
          "status",
          "url"
        ]
      },
      "TemplateMedia": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "ID of the header media. Use it in `components.header.media_id`.",
            "example": "tmedia_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "format": {
            "type": "string",
            "enum": [
              "image",
              "video",
              "document"
            ],
            "description": "Format: `image`, `video` or `document`."
          },
          "size_bytes": {
            "type": "number",
            "description": "File size, in bytes."
          },
          "content_type": {
            "type": "string",
            "description": "MIME type of the file.",
            "example": "image/png"
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the file was uploaded.",
            "example": "2026-09-04T13:22:41.031Z"
          }
        },
        "required": [
          "id",
          "format",
          "size_bytes",
          "content_type",
          "created_at"
        ]
      },
      "Usage": {
        "type": "object",
        "properties": {
          "from_date": {
            "description": "Start of the period (inclusive).",
            "type": "string",
            "example": "2026-09-01"
          },
          "to_date": {
            "description": "End of the period (exclusive).",
            "type": "string",
            "example": "2026-10-01"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "metric",
                "channel_type",
                "provider",
                "quantity",
                "unit"
              ],
              "properties": {
                "metric": {
                  "type": "string",
                  "description": "Metric measured.",
                  "example": "message.sent"
                },
                "channel_type": {
                  "type": "string",
                  "nullable": true,
                  "description": "Channel type, or `null`.",
                  "example": "whatsapp"
                },
                "provider": {
                  "type": "string",
                  "nullable": true,
                  "description": "Provider, or `null`.",
                  "example": "whatsapp_cloud"
                },
                "quantity": {
                  "type": "number",
                  "description": "Quantity in the period.",
                  "example": 1840
                },
                "unit": {
                  "type": "string",
                  "description": "Unit of the metric.",
                  "example": "message"
                }
              }
            },
            "description": "One row per combination of metric, channel type and provider."
          }
        },
        "required": [
          "from_date",
          "to_date",
          "data"
        ]
      },
      "Whoami": {
        "type": "object",
        "properties": {
          "organization_id": {
            "type": "string",
            "description": "Organization that owns the key.",
            "example": "org_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "project_id": {
            "type": "string",
            "description": "Project the key belongs to.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "api_key_id": {
            "type": "string",
            "description": "Key ID.",
            "example": "key_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "messages:read",
                "messages:write",
                "channels:read",
                "channels:write",
                "events:read",
                "webhooks:write",
                "usage:read",
                "templates:read",
                "templates:write",
                "media:read",
                "media:write"
              ]
            },
            "description": "Scopes granted to the key."
          }
        },
        "required": [
          "organization_id",
          "project_id",
          "api_key_id",
          "scopes"
        ]
      },
      "PartnerProject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Project ID.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "name": {
            "type": "string",
            "description": "Display name of the project.",
            "example": "Acme Store"
          },
          "external_ref": {
            "type": "string",
            "description": "Your ID for the customer. Unique in the organization and set once.",
            "example": "lead_123"
          },
          "environment": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ],
            "description": "Project environment. Partner API projects are always `live`.",
            "example": "live"
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the project was created.",
            "example": "2026-09-04T13:22:41.031Z"
          }
        },
        "required": [
          "id",
          "name",
          "external_ref",
          "environment",
          "created_at"
        ]
      },
      "PartnerProjectList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PartnerProject"
            },
            "description": "Projects on this page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more pages."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor of the next page, or `null` on the last one."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "PartnerProjectDetail": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Project ID.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "name": {
            "type": "string",
            "description": "Display name of the project.",
            "example": "Acme Store"
          },
          "external_ref": {
            "type": "string",
            "description": "Your ID for the customer.",
            "example": "lead_123"
          },
          "environment": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ],
            "description": "Project environment.",
            "example": "live"
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the project was created.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "status"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Channel ID.",
                  "example": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
                },
                "status": {
                  "type": "string",
                  "description": "Channel state: `pending`, `active`, `degraded` or `disabled`.",
                  "example": "active"
                }
              }
            },
            "description": "Channels of the project, in any state. An `active` channel means the customer finished connecting."
          }
        },
        "required": [
          "id",
          "name",
          "external_ref",
          "environment",
          "created_at",
          "channels"
        ]
      },
      "PartnerProjectDeleting": {
        "type": "object",
        "properties": {
          "project_id": {
            "type": "string",
            "description": "Project being deleted.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "status": {
            "type": "string",
            "enum": [
              "deleting"
            ],
            "description": "Always `deleting`. The project is still there, partly deleted. Repeat the call until you get `204`.",
            "example": "deleting"
          }
        },
        "required": [
          "project_id",
          "status"
        ]
      },
      "PartnerChannelList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "project_id",
                "external_ref",
                "address",
                "status",
                "status_reason_code",
                "connection_mode",
                "disconnection_reason",
                "created_at"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Channel ID.",
                  "example": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
                },
                "project_id": {
                  "type": "string",
                  "description": "Project that owns the channel.",
                  "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
                },
                "external_ref": {
                  "type": "string",
                  "description": "The `external_ref` of the project.",
                  "example": "lead_123"
                },
                "address": {
                  "type": "string",
                  "description": "Channel address, in E.164.",
                  "example": "+5581988888888"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "pending",
                    "active",
                    "degraded",
                    "disabled"
                  ],
                  "description": "Channel state: `pending`, `active`, `degraded` or `disabled`.",
                  "example": "active"
                },
                "status_reason_code": {
                  "type": "string",
                  "enum": [
                    "provider_auth_repeated_failure",
                    "disconnected_by_customer",
                    "offboarded"
                  ],
                  "nullable": true,
                  "description": "Why the channel is `degraded` or `disabled`: `provider_auth_repeated_failure` (`degraded`), `disconnected_by_customer` or `offboarded` (`disabled`). `null` otherwise.",
                  "example": null
                },
                "connection_mode": {
                  "type": "string",
                  "enum": [
                    "cloud_api",
                    "coexistence"
                  ],
                  "description": "How the number was connected: `cloud_api` or `coexistence` (the number stays in the WhatsApp Business app).",
                  "example": "cloud_api"
                },
                "disconnection_reason": {
                  "type": "string",
                  "enum": [
                    "account_disconnected",
                    "business_downgrade",
                    "change_number",
                    "companion_inactivity",
                    "primary_inactivity",
                    "user_re_registered",
                    "unknown"
                  ],
                  "nullable": true,
                  "description": "The reason the provider gave for the disconnection: `account_disconnected`, `business_downgrade`, `change_number`, `companion_inactivity`, `primary_inactivity`, `user_re_registered` or `unknown`. `null` when there was no disconnection.",
                  "example": null
                },
                "created_at": {
                  "format": "date-time",
                  "type": "string",
                  "description": "When the channel was created.",
                  "example": "2026-09-04T13:22:41.031Z"
                }
              }
            },
            "description": "Channels on this page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more pages."
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor of the next page, or `null` on the last one."
          }
        },
        "required": [
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "PartnerProjectApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Key ID.",
            "example": "key_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "project_id": {
            "type": "string",
            "description": "Project the key belongs to.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "name": {
            "type": "string",
            "nullable": true,
            "description": "The name you gave the key, or `null`.",
            "example": "Acme Store"
          },
          "key_prefix": {
            "type": "string",
            "description": "First characters of the key, safe to display.",
            "example": "rt_live_abc"
          },
          "last_four": {
            "type": "string",
            "description": "Last four characters of the key.",
            "example": "k3xQ"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "messages:read",
                "messages:write",
                "channels:read",
                "channels:write",
                "events:read",
                "webhooks:write",
                "usage:read",
                "templates:read",
                "templates:write",
                "media:read",
                "media:write"
              ]
            },
            "description": "Scopes granted to the project key."
          },
          "expires_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the key expires, or `null` if it does not."
          },
          "ip_allowlist": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Allowed IP addresses or CIDR blocks. An empty list applies no restriction."
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the key was created.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "revoked_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the key was revoked, or `null` while it is active."
          },
          "last_used_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "Last use of the key, rounded to the minute, or `null`."
          }
        },
        "required": [
          "id",
          "project_id",
          "name",
          "key_prefix",
          "last_four",
          "scopes",
          "expires_at",
          "ip_allowlist",
          "created_at",
          "revoked_at",
          "last_used_at"
        ]
      },
      "PartnerProjectApiKeyWithSecret": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Key ID.",
            "example": "key_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "project_id": {
            "type": "string",
            "description": "Project the key belongs to.",
            "example": "proj_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
          },
          "name": {
            "type": "string",
            "nullable": true,
            "description": "The name you gave the key, or `null`.",
            "example": "Acme Store"
          },
          "key_prefix": {
            "type": "string",
            "description": "First characters of the key, safe to display.",
            "example": "rt_live_abc"
          },
          "last_four": {
            "type": "string",
            "description": "Last four characters of the key.",
            "example": "k3xQ"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "messages:read",
                "messages:write",
                "channels:read",
                "channels:write",
                "events:read",
                "webhooks:write",
                "usage:read",
                "templates:read",
                "templates:write",
                "media:read",
                "media:write"
              ]
            },
            "description": "Scopes granted to the project key."
          },
          "expires_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the key expires, or `null` if it does not."
          },
          "ip_allowlist": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Allowed IP addresses or CIDR blocks. An empty list applies no restriction."
          },
          "created_at": {
            "format": "date-time",
            "type": "string",
            "description": "When the key was created.",
            "example": "2026-09-04T13:22:41.031Z"
          },
          "revoked_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "When the key was revoked, or `null` while it is active."
          },
          "last_used_at": {
            "format": "date-time",
            "type": "string",
            "nullable": true,
            "description": "Last use of the key, rounded to the minute, or `null`."
          },
          "secret": {
            "type": "string",
            "description": "The full API key. Shown **only now**. Store it safely.",
            "example": "rt_live_..."
          }
        },
        "required": [
          "id",
          "project_id",
          "name",
          "key_prefix",
          "last_four",
          "scopes",
          "expires_at",
          "ip_allowlist",
          "created_at",
          "revoked_at",
          "last_used_at",
          "secret"
        ]
      }
    }
  }
}
