openapi: 3.1.0
info:
  title: Whitelabel WhatsApp Cloud API
  version: "1"
  description: >-
    Tenant-key surface. One tenant connects many businesses (customers) to
    WhatsApp.

    Graph version pinned by the server is v24.0.


    Written from route handlers and Zod schemas in whitelabel-whatsapp-cloud-api

    as of 2026-10-21. Stored rows and Meta pass-through objects can include
    extra properties.

    Admin routes are omitted. A tenant API key is rejected there with 403. Do
    not call those routes.


    Successful JSON responses are wrapped in {"data": ...}.

    Paginated lists also return "meta". Errors are not wrapped in "data".
  license:
    name: Proprietary
servers:
  - url: https://wa.vitral.dev
    description: Production
tags:
  - name: Health
  - name: Customers
  - name: Setup links
  - name: Branding
  - name: Embedded Signup
  - name: Phone numbers
  - name: Messages
  - name: Templates
  - name: Media
  - name: Webhooks
  - name: API keys
  - name: Usage
  - name: Billing
security:
  - bearerAuth: []
paths:
  /health:
    get:
      tags:
        - Health
      security: []
      summary: Liveness
      operationId: getHealth
      responses:
        "200":
          description: Database and Redis checks.
          content:
            application/json:
              schema:
                type: object
                required:
                  - status
                  - uptime
                  - timestamp
                  - checks
                properties:
                  status:
                    type: string
                    enum:
                      - ok
                      - degraded
                      - error
                  uptime:
                    type: number
                  timestamp:
                    type: string
                    format: date-time
                  checks:
                    type: object
                    required:
                      - database
                      - redis
                    properties:
                      database:
                        $ref: "#/components/schemas/HealthCheck"
                      redis:
                        $ref: "#/components/schemas/HealthCheck"
        "503":
          description: status is degraded (one check failed) or error (both failed). Same
            body.
  /api/v1/customers:
    get:
      tags:
        - Customers
      summary: List customers
      operationId: listCustomers
      parameters:
        - $ref: "#/components/parameters/search"
        - $ref: "#/components/parameters/page"
        - $ref: "#/components/parameters/limit"
      responses:
        "200":
          description: Page of customers.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CustomerPage"
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
    post:
      tags:
        - Customers
      summary: Create a business sub-account
      operationId: createCustomer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CustomerCreate"
      responses:
        "201":
          description: Created.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Customer"
        "409":
          $ref: "#/components/responses/Error"
  /api/v1/customers/{id}:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Customers
      summary: Get customer
      operationId: getCustomer
      responses:
        "200":
          description: Customer
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Customer"
        "404":
          $ref: "#/components/responses/Error"
    patch:
      tags:
        - Customers
      summary: Update customer
      operationId: updateCustomer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CustomerUpdate"
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Customer"
    delete:
      tags:
        - Customers
      summary: Delete customer
      operationId: deleteCustomer
      responses:
        "204":
          description: Deleted. Linked phone numbers keep their rows; customerId becomes
            null.
  /api/v1/customers/{customerId}/setup-links:
    parameters:
      - $ref: "#/components/parameters/customerId"
    get:
      tags:
        - Setup links
      summary: List setup links
      description: Stored rows. Includes tokenHash (not the raw token). The raw token
        is only on create.
      operationId: listSetupLinks
      responses:
        "200":
          description: Links
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/SetupLink"
    post:
      tags:
        - Setup links
      summary: Create a setup link
      description: |-
        201 data is { id, token, url }. Creating a link revokes that customer's
        other ACTIVE links only when they have not been opened. IN_PROGRESS
        links are not revoked.
      operationId: createSetupLink
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SetupLinkCreate"
      responses:
        "201":
          description: Token is returned only here.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/SetupLinkCreated"
  /api/v1/customers/{customerId}/setup-links/{id}:
    parameters:
      - $ref: "#/components/parameters/customerId"
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Setup links
      summary: Get setup link
      description: |-
        repair is a sibling of data when action is pending or needs_reconnect.
        pending means the link has not been used. needs_reconnect means a
        finished attempt could not attach the phone.
        The public status route nests that same object inside data.
      operationId: getSetupLink
      responses:
        "200":
          description: Link
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/SetupLink"
                  repair:
                    $ref: "#/components/schemas/Repair"
    delete:
      tags:
        - Setup links
      summary: Revoke setup link
      operationId: revokeSetupLink
      responses:
        "204":
          description: Revoked
    patch:
      tags:
        - Setup links
      summary: Update an ACTIVE setup link
      description: >-
        Scope setup-links:manage. Only ACTIVE links. status REVOKED revokes the
        link.

        status USED is rejected. expiresAt and expiresInDays cannot both be
        sent.

        expiresAt must be within 30 days. Redirect URLs must match the
        allowlist.
      operationId: updateSetupLink
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SetupLinkPatch"
      responses:
        "200":
          description: Updated row. tokenHash is included. The raw token is not.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/SetupLink"
        "400":
          description: Validation, including a redirect outside the allowlist or status
            other than REVOKED.
        "409":
          description: Link is not ACTIVE. INVALID_STATE_TRANSITION.
  /api/v1/customers/{customerId}/setup-links/{id}/regenerate:
    parameters:
      - $ref: "#/components/parameters/customerId"
      - $ref: "#/components/parameters/id"
    post:
      tags:
        - Setup links
      summary: Issue a new setup link from this one
      description: |-
        Scope setup-links:manage. Copies language, branding, redirects, and
        allowedConnectionTypes. Revokes unopened ACTIVE links. Does not revoke
        IN_PROGRESS, USED, or an opened ACTIVE link. Revokes an EXPIRED source.
        Returns the new token once.
      operationId: regenerateSetupLink
      responses:
        "201":
          description: New token. Shown once.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/SetupLinkCreated"
  /api/v1/branding:
    get:
      tags:
        - Branding
      summary: List branding profiles
      description: Scope setup-links:manage.
      operationId: listBranding
      responses:
        "200":
          description: Profiles
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Branding"
    post:
      tags:
        - Branding
      summary: Create branding profile
      operationId: createBranding
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BrandingCreate"
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Branding"
  /api/v1/branding/{id}:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Branding
      summary: Get branding profile
      operationId: getBranding
      responses:
        "200":
          description: Profile
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Branding"
    patch:
      tags:
        - Branding
      summary: Update branding profile
      operationId: updateBranding
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BrandingUpdate"
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Branding"
    delete:
      tags:
        - Branding
      summary: Delete branding profile
      operationId: deleteBranding
      responses:
        "204":
          description: Deleted
  /api/v1/setup/public/{token}:
    parameters:
      - $ref: "#/components/parameters/token"
    get:
      tags:
        - Embedded Signup
      security: []
      summary: Headless Embedded Signup config
      operationId: getPublicSetup
      responses:
        "200":
          description: Meta app id and config id for FB.login. No API key.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/PublicSetupConfig"
        "404":
          description: Unknown token. NOT_FOUND.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "410":
          description: Expired, used, revoked, or status EXPIRED. SETUP_LINK_EXPIRED or
            SETUP_LINK_INVALID.
  /api/v1/setup/public/{token}/finalize:
    parameters:
      - $ref: "#/components/parameters/token"
    post:
      tags:
        - Embedded Signup
      security: []
      summary: Exchange the Embedded Signup code
      description: >-
        Response is not wrapped in { data }. Success is status processing plus
        binding.

        Failure is status failed plus error. binding.phone.id is the phone the
        hosted flow stores.
      operationId: finalizePublicSetup
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - code
              properties:
                code:
                  type: string
                connectionType:
                  type: string
                  enum:
                    - coexistence
                    - dedicated
                  description: Optional. Required only when it must be one of
                    allowedConnectionTypes. Omitted with both types allowed
                    stores null.
                sessionInfo:
                  $ref: "#/components/schemas/SessionInfo"
      responses:
        "200":
          description: Processing or failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    description: processing or failed
                  setupLinkId:
                    type: string
                  error:
                    type: string
                  errorCode:
                    type: string
                    description: Additive. Present when status is failed.
                  redirectUrl:
                    type: string
                    description: Additive. Present when a failure redirect is configured.
                  binding:
                    type: object
                    additionalProperties: true
                    description: Present when status is processing. Includes phone.
        "404":
          $ref: "#/components/responses/Error"
        "410":
          description: Token expired or no longer active.
  /api/v1/setup/public/{token}/status:
    parameters:
      - $ref: "#/components/parameters/token"
    get:
      tags:
        - Embedded Signup
      security: []
      summary: Poll setup status
      description: Works after the link is USED. No API key.
      operationId: getPublicSetupStatus
      responses:
        "200":
          description: Status
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      status:
                        $ref: "#/components/schemas/SetupLinkStatus"
                      whatsappSetupStatus:
                        $ref: "#/components/schemas/WhatsappSetupStatus"
                      whatsappSetupError:
                        type:
                          - string
                          - "null"
                      phoneNumberId:
                        type:
                          - string
                          - "null"
                      connectionType:
                        type:
                          - string
                          - "null"
                        enum:
                          - coexistence
                          - dedicated
                          - null
                      repair:
                        $ref: "#/components/schemas/Repair"
        "404":
          description: Unknown token. This route does not return 410 for an expired link.
  /setup/{token}:
    parameters:
      - $ref: "#/components/parameters/token"
    get:
      tags:
        - Embedded Signup
      security: []
      summary: Hosted setup page
      description: |-
        Sets a session cookie and redirects to /setup/start. HTML, not JSON.
        404 when the token is unknown. 410 when it is expired, used, or revoked.
        302 to failureRedirectUrl when that URL is set for those blocked states,
        except USED+COMPLETED, which stays on the already-connected page.
      operationId: getHostedSetup
      responses:
        "302":
          description: Redirect to /setup/start
        "410":
          description: HTML gone page
  /api/v1/embedded-signup/token-exchange:
    post:
      tags:
        - Embedded Signup
      summary: Exchange a code without a setup link
      description: |-
        Scope phone_numbers:write. Does not set PhoneNumber.customerId.
        Prefer the setup-link finalize path when the business is a Customer.
      operationId: embeddedSignupTokenExchange
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - code
              properties:
                code:
                  type: string
                wabaId:
                  type: string
                waPhoneNumberId:
                  type: string
                phoneNumber:
                  type: string
                displayName:
                  type: string
                pin:
                  type: string
                  pattern: ^[0-9]{6}$
                sessionInfo:
                  $ref: "#/components/schemas/SessionInfo"
      responses:
        "201":
          description: Session plus binding.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    additionalProperties: true
        "400":
          $ref: "#/components/responses/Error"
        "402":
          $ref: "#/components/responses/Error"
  /api/v1/embedded-signup/register:
    post:
      tags:
        - Embedded Signup
      summary: Register a phone on an existing session
      operationId: embeddedSignupRegister
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - sessionId
                - waPhoneNumberId
                - phoneNumber
              properties:
                sessionId:
                  type: string
                waPhoneNumberId:
                  type: string
                phoneNumber:
                  type: string
                displayName:
                  type: string
                pin:
                  type: string
                  pattern: ^[0-9]{6}$
      responses:
        "201":
          description: Session
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    additionalProperties: true
        "400":
          $ref: "#/components/responses/Error"
        "402":
          $ref: "#/components/responses/Error"
  /api/v1/embedded-signup/finish-binding:
    post:
      tags:
        - Embedded Signup
      summary: Repair a half-bound WABA
      operationId: embeddedSignupFinishBinding
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionId:
                  type: string
                wabaId:
                  type: string
                setupLinkId:
                  type: string
                waPhoneNumberId:
                  type: string
      responses:
        "200":
          description: Binding.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    additionalProperties: true
        "400":
          $ref: "#/components/responses/Error"
        "402":
          $ref: "#/components/responses/Error"
  /api/v1/phone-numbers:
    get:
      tags:
        - Phone numbers
      summary: List phone numbers
      description: Scope phone_numbers:read. Returns stored rows, not a trimmed DTO.
      operationId: listPhoneNumbers
      responses:
        "200":
          description: Numbers on this tenant
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/PhoneNumber"
  /api/v1/phone-numbers/{id}:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Phone numbers
      summary: Get phone number
      operationId: getPhoneNumber
      responses:
        "200":
          description: Phone
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/PhoneNumber"
        "404":
          $ref: "#/components/responses/Error"
    patch:
      tags:
        - Phone numbers
      summary: Update a phone number
      description: >-
        Scope phone_numbers:write. `botPauseMinutesOnEcho` is how long a
        WhatsApp

        Business app reply pauses tenant bots on this number. Null uses the

        deployment default (30 minutes). 0 disables the pause. Integers 0
        through 1440.
      operationId: updatePhoneNumber
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                displayName:
                  type: string
                maxMessagesPerSecond:
                  type: integer
                  minimum: 1
                  maximum: 500
                status:
                  $ref: "#/components/schemas/PhoneNumberStatus"
                botPauseMinutesOnEcho:
                  type:
                    - integer
                    - "null"
                  minimum: 0
                  maximum: 1440
      responses:
        "200":
          description: Updated phone
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/PhoneNumber"
        "400":
          $ref: "#/components/responses/Error"
        "402":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
        "404":
          $ref: "#/components/responses/Error"
  /api/v1/phone-numbers/{id}/status:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Phone numbers
      summary: Phone status
      operationId: getPhoneNumberStatus
      responses:
        "200":
          description: Status fields only
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                      status:
                        $ref: "#/components/schemas/PhoneNumberStatus"
                      isVerified:
                        type: boolean
                      qualityRating:
                        type:
                          - string
                          - "null"
  /api/v1/phone-numbers/{id}/register:
    parameters:
      - $ref: "#/components/parameters/id"
    post:
      tags:
        - Phone numbers
      summary: Register with a 6-digit PIN
      description: |-
        Scope phone_numbers:write. 133010 and 133016 map to 422 and 429.
        402 PHONE_NUMBER_LIMIT when activating this number would pass the plan's
        WhatsApp number limit (checked before Meta is called).
      operationId: registerPhoneNumber
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - pin
              properties:
                pin:
                  type: string
                  pattern: ^[0-9]{6}$
      responses:
        "200":
          description: Phone row
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/PhoneNumber"
        "402":
          $ref: "#/components/responses/Error"
        "422":
          $ref: "#/components/responses/Error"
        "429":
          $ref: "#/components/responses/Error"
  /api/v1/phone-numbers/{id}/check-connection:
    parameters:
      - $ref: "#/components/parameters/id"
    post:
      tags:
        - Phone numbers
      summary: Check connection and finish binding if needed
      description: Does not call register again when the phone is already stored locally.
      operationId: checkPhoneConnection
      responses:
        "200":
          description: Binding summary
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      phone:
                        $ref: "#/components/schemas/PhoneNumber"
                      wabaId:
                        type: string
                      webhookSubscribed:
                        type: boolean
                      grantedGraphScopes:
                        type: array
                        items:
                          type: string
                      missingGraphScopes:
                        type: array
                        items:
                          type: string
                      missingTenantScopes:
                        type: array
                        items:
                          type: string
                      phonePickReason:
                        type: string
                      registered:
                        type: boolean
                      pinNotReset:
                        type: boolean
  /api/v1/conversations/window:
    get:
      tags:
        - Messages
      summary: Read the 24-hour window for a recipient
      description: >-
        Scope conversations:read. windowOpen false means a non-template send is
        rejected.

        conversationId is null when this recipient has no conversation on that
        phone.
      operationId: getConversationWindow
      parameters:
        - name: phoneNumberId
          in: query
          required: true
          schema:
            type: string
          description: Whitelabel WhatsApp Cloud API phone id.
        - name: to
          in: query
          required: true
          schema:
            type: string
          description: Recipient digits, or a business-scoped user id.
      responses:
        "200":
          description: Window state
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    required:
                      - waId
                      - windowOpen
                    properties:
                      conversationId:
                        type:
                          - string
                          - "null"
                      contactId:
                        type:
                          - string
                          - "null"
                      waId:
                        type: string
                      windowOpen:
                        type: boolean
                      windowExpiresAt:
                        type:
                          - string
                          - "null"
                        format: date-time
                      lastInboundCustomerMsgAt:
                        type:
                          - string
                          - "null"
                        format: date-time
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
  /api/v1/conversations:
    get:
      tags:
        - Messages
      summary: List conversations
      description: |-
        Scope conversations:read. Each row includes lastBusinessAppReplyAt,
        humanActiveUntil, botResumedAt, and botPaused. lastBusinessAppReplyAt
        is the last WhatsApp Business app reply that started or extended the
        pause. botPaused is true when humanActiveUntil is in the future. This
        API does not block sends while the pause is active.
      operationId: listConversations
      parameters:
        - name: phoneNumberId
          in: query
          schema:
            type: string
        - name: contactId
          in: query
          schema:
            type: string
        - name: page
          in: query
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 50
      responses:
        "200":
          description: Conversations on this tenant
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - meta
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Conversation"
                  meta:
                    $ref: "#/components/schemas/PageMeta"
  /api/v1/conversations/{id}:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Messages
      summary: Get a conversation
      description: >-
        Scope conversations:read. Adds botPaused next to the stored pause
        columns.

        Another tenant's id is 404.
      operationId: getConversation
      responses:
        "200":
          description: Conversation
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Conversation"
        "404":
          $ref: "#/components/responses/Error"
  /api/v1/conversations/{id}/bot-resume:
    parameters:
      - $ref: "#/components/parameters/id"
    post:
      tags:
        - Messages
      summary: Resume the bot after a human takeover
      description: |-
        Scope conversations:read for now. Clears a pause that is still in the
        future: sets humanActiveUntil to null and botResumedAt to now, and
        sends conversation.bot_resumed once (contactId and waId included). A
        second call, or a call when the pause has already expired, returns 200
        and does not send the event again. Another tenant's id is 404. A later
        WhatsApp Business app reply starts a new pause. This API does not block
        sends.
      operationId: resumeConversationBot
      responses:
        "200":
          description: Conversation after resume
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Conversation"
        "404":
          $ref: "#/components/responses/Error"
  /api/v1/messages:
    get:
      tags:
        - Messages
      summary: List messages
      operationId: listMessages
      parameters:
        - name: phoneNumberId
          in: query
          schema:
            type: string
        - name: contactId
          in: query
          schema:
            type: string
        - name: conversationId
          in: query
          schema:
            type: string
        - name: direction
          in: query
          schema:
            type: string
            enum:
              - INBOUND
              - OUTBOUND
        - name: status
          in: query
          schema:
            type: string
        - $ref: "#/components/parameters/page"
        - $ref: "#/components/parameters/limit"
      responses:
        "200":
          description: Page
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessagePage"
    post:
      tags:
        - Messages
      summary: Queue a message
      description: >-
        201 means queued, not delivered. Send Idempotency-Key to make a retry
        safe:

        the same key and body return the first message (header
        Idempotent-Replayed: true);

        the same key with another body is 409 IDEMPOTENCY_KEY_REUSED.

        Non-template types fail with VALIDATION_ERROR when the 24-hour window is
        closed.
      operationId: sendMessage
      parameters:
        - $ref: "#/components/parameters/idempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SendMessage"
      responses:
        "201":
          description: Pending message row
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Message"
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/messages/batch:
    post:
      tags:
        - Messages
      summary: Queue up to 100 messages
      description: >-
        Sequential. A mid-batch error leaves earlier messages queued.

        With Idempotency-Key, item i uses `<key>:<i>`; retrying with the same
        key

        replays queued items and sends only the rest.
      operationId: sendMessageBatch
      parameters:
        - $ref: "#/components/parameters/idempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - phoneNumberId
                - messages
              properties:
                phoneNumberId:
                  type: string
                messages:
                  type: array
                  minItems: 1
                  maxItems: 100
                  items:
                    $ref: "#/components/schemas/SendMessageBody"
      responses:
        "201":
          description: Rows
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Message"
  /api/v1/messages/{id}:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Messages
      summary: Get message
      operationId: getMessage
      responses:
        "200":
          description: Message
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Message"
        "404":
          $ref: "#/components/responses/Error"
  /api/v1/messages/{id}/mark-read:
    parameters:
      - $ref: "#/components/parameters/id"
    post:
      tags:
        - Messages
      summary: Send a read receipt
      description: Requires wamId. Synchronous Graph call.
      operationId: markMessageRead
      responses:
        "200":
          description: Message
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Message"
  /api/v1/messages/{id}/react:
    parameters:
      - $ref: "#/components/parameters/id"
    post:
      tags:
        - Messages
      summary: React to a message
      operationId: reactToMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - emoji
              properties:
                emoji:
                  type: string
                  minLength: 1
      responses:
        "201":
          description: Reaction message row
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Message"
  /api/v1/templates:
    get:
      tags:
        - Templates
      summary: List templates
      description: |-
        phoneNumberId limits the list to that phone's WABA.
        Omitting both filters returns every template on the tenant.
      operationId: listTemplates
      parameters:
        - name: wabaId
          in: query
          schema:
            type: string
        - name: phoneNumberId
          in: query
          schema:
            type: string
        - name: status
          in: query
          schema:
            type: string
        - $ref: "#/components/parameters/page"
        - $ref: "#/components/parameters/limit"
      responses:
        "200":
          description: Page
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplatePage"
    post:
      tags:
        - Templates
      summary: Create a template on a WABA
      description: Stored status is PENDING until a sync updates it. Scope templates:write.
      operationId: createTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TemplateCreate"
      responses:
        "201":
          description: Template
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Template"
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/templates/sync:
    post:
      tags:
        - Templates
      summary: Enqueue a template sync
      operationId: syncTemplates
      responses:
        "202":
          description: Enqueued
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      message:
                        type: string
  /api/v1/templates/{id}:
    parameters:
      - $ref: "#/components/parameters/id"
    get:
      tags:
        - Templates
      summary: Get template
      operationId: getTemplate
      responses:
        "200":
          description: Template
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Template"
    patch:
      tags:
        - Templates
      summary: Update template components or category
      operationId: updateTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                components:
                  type: array
                  items:
                    type: object
                    additionalProperties: true
                category:
                  type: string
                  enum:
                    - MARKETING
                    - UTILITY
                    - AUTHENTICATION
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/Template"
    delete:
      tags:
        - Templates
      summary: Delete template
      operationId: deleteTemplate
      responses:
        "204":
          description: Deleted
  /api/v1/webhook-config:
    get:
      tags:
        - Webhooks
      summary: Get webhook config
      description: Does not return the secret. Scope webhooks:manage.
      operationId: getWebhookConfig
      responses:
        "200":
          description: Config
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/WebhookConfig"
    put:
      tags:
        - Webhooks
      summary: Set webhook URL and secret
      operationId: putWebhookConfig
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - webhookUrl
              properties:
                webhookUrl:
                  type:
                    - string
                    - "null"
                  format: uri
                webhookSecret:
                  type:
                    - string
                    - "null"
                  minLength: 16
                  description: Omit to keep the current secret. Null clears it.
      responses:
        "200":
          description: Saved. Circuit breaker reset.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      webhookUrl:
                        type:
                          - string
                          - "null"
                      hasSecret:
                        type: boolean
  /api/v1/webhook-config/deliveries:
    get:
      tags:
        - Webhooks
      summary: List delivery attempts
      description: Query uses pageSize, not limit. meta.limit echoes pageSize.
      operationId: listWebhookDeliveries
      parameters:
        - $ref: "#/components/parameters/page"
        - name: pageSize
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
        - name: status
          in: query
          schema:
            type: string
            enum:
              - PENDING
              - DELIVERED
              - FAILED
              - DLQ
        - name: eventType
          in: query
          schema:
            type: string
      responses:
        "200":
          description: Deliveries
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - meta
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/WebhookDelivery"
                  meta:
                    $ref: "#/components/schemas/PageMeta"
  /api/v1/webhook-config/deliveries/{id}/replay:
    post:
      tags:
        - Webhooks
      summary: Replay one delivery
      description: |-
        Any status, including DELIVERED. Same X-Vitral-WhatsApp-Delivery-Id, plus
        X-Vitral-WhatsApp-Replay: true. Delayed while the circuit is open.
      operationId: replayWebhookDelivery
      parameters:
        - $ref: "#/components/parameters/id"
      responses:
        "202":
          description: Queued
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReplayResult"
        "404":
          $ref: "#/components/responses/Error"
  /api/v1/webhook-config/deliveries/replay:
    post:
      tags:
        - Webhooks
      summary: Replay deliveries in bulk
      description: Pass ids or at least one filter. Oldest first, at most limit per call.
      operationId: replayWebhookDeliveries
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ids:
                  type: array
                  maxItems: 1000
                  items:
                    type: string
                statuses:
                  type: array
                  items:
                    type: string
                    enum:
                      - PENDING
                      - DELIVERED
                      - FAILED
                      - DLQ
                eventType:
                  type: string
                from:
                  type: string
                  format: date-time
                to:
                  type: string
                  format: date-time
                limit:
                  type: integer
                  minimum: 1
                  maximum: 1000
                  default: 100
      responses:
        "202":
          description: Queued
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReplayResult"
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/webhook-config/rotate-secret:
    post:
      tags:
        - Webhooks
      summary: Rotate the webhook signing secret
      description: |-
        Scope `webhooks:manage`. Returns the new secret once. The previous
        secret stops verifying immediately. GET /webhook-config still does
        not return the secret.
      operationId: rotateWebhookSecret
      responses:
        "200":
          description: New secret. Shown once.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    required:
                      - webhookSecret
                    properties:
                      webhookSecret:
                        type: string
                        minLength: 16
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
  /api/v1/api-keys:
    get:
      tags:
        - API keys
      summary: List this tenant's API keys
      description: |-
        Scope `api_keys:read` or `api_keys:manage`. Returns `keyPrefix`,
        `scopes`, `createdAt`, and `lastUsedAt`. Also `id`, `name`,
        `expiresAt`, and `revokedAt`. Never the raw key, the hash, or
        `lastUsedIp`.
      operationId: listApiKeys
      responses:
        "200":
          description: Keys for the caller tenant.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/ApiKeyPublic"
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
    post:
      tags:
        - API keys
      summary: Create an API key for this tenant
      description: |-
        Scope `api_keys:manage`. `rawKey` is returned once, beside `data`.
        A tenant key can grant only scopes it already has. Omitting `scopes`
        copies the caller’s scopes.
      operationId: createApiKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ApiKeyCreate"
      responses:
        "201":
          description: Created. Save `rawKey` now.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - rawKey
                properties:
                  data:
                    allOf:
                      - $ref: "#/components/schemas/ApiKeyPublic"
                      - type: object
                        required:
                          - tenantId
                        properties:
                          tenantId:
                            type: string
                  rawKey:
                    type: string
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
  /api/v1/api-keys/{id}:
    delete:
      tags:
        - API keys
      summary: Revoke an API key
      description: |-
        Scope `api_keys:manage`. The key must belong to the caller tenant.
        Revoking the key that authenticated this request fails with 409
        when it is the last active key (not revoked, not expired). Revoking
        a different key is allowed.
      operationId: revokeApiKey
      parameters:
        - $ref: "#/components/parameters/id"
      responses:
        "204":
          description: Revoked.
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
        "404":
          $ref: "#/components/responses/Error"
        "409":
          $ref: "#/components/responses/Error"
  /api/v1/webhooks/meta:
    post:
      tags:
        - Webhooks
      security: []
      summary: Meta webhook ingress
      description: |-
        Called by Meta, not by integrators. `X-Hub-Signature-256` must be
        `sha256=` plus HMAC-SHA256 of the raw body using the app secret.
        A missing or invalid signature is not stored. `true` returns 401.
        A valid signature is stored before the 200 `EVENT_RECEIVED`, then
        processed asynchronously. If it cannot be stored, 503 so Meta retries.
      operationId: postMetaWebhook
      parameters:
        - name: X-Hub-Signature-256
          in: header
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Signature matched. Body is the text EVENT_RECEIVED.
          content:
            text/plain:
              schema:
                type: string
                enum:
                  - EVENT_RECEIVED
        "401":
          description: Invalid signature. Not processed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "503":
          description: Signature matched but the event could not be stored. Meta retries.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /api/v1/webhook-config/test:
    post:
      tags:
        - Webhooks
      summary: POST a webhook.test event
      description: Synchronous. Does not create a delivery row.
      operationId: testWebhook
      responses:
        "200":
          description: Result. HTTP 200 even when the tenant webhook URL failed.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      success:
                        type: boolean
                      statusCode:
                        type: integer
                      error:
                        type: string
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/media:
    post:
      tags:
        - Media
      summary: Upload a file to Meta
      description: >-
        multipart/form-data with a `file` part (optional text fields `type` and
        `kind`),

        or the raw bytes with the file's Content-Type. Meta's per-kind size
        limits are

        checked first. Use the returned mediaId in a send body.
      operationId: uploadMedia
      security:
        - bearerAuth: []
      parameters:
        - name: phoneNumberId
          in: query
          required: true
          schema:
            type: string
        - name: filename
          in: query
          description: Raw uploads only.
          schema:
            type: string
        - name: kind
          in: query
          schema:
            $ref: "#/components/schemas/MediaKind"
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                type:
                  type: string
                kind:
                  $ref: "#/components/schemas/MediaKind"
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        "201":
          description: Uploaded
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/UploadedMedia"
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/media/from-url:
    post:
      tags:
        - Media
      summary: Fetch a public URL and upload it to Meta
      description: Only public http(s) addresses. Private, loopback, link-local and
        metadata addresses are refused.
      operationId: uploadMediaFromUrl
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - phoneNumberId
                - url
              properties:
                phoneNumberId:
                  type: string
                url:
                  type: string
                  format: uri
                mimeType:
                  type: string
                filename:
                  type: string
                kind:
                  $ref: "#/components/schemas/MediaKind"
      responses:
        "201":
          description: Uploaded
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    allOf:
                      - $ref: "#/components/schemas/UploadedMedia"
                      - type: object
                        properties:
                          sourceUrl:
                            type: string
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/media/assets:
    get:
      tags:
        - Media
      summary: List stored media copies
      operationId: listMediaAssets
      parameters:
        - name: messageId
          in: query
          schema:
            type: string
        - name: phoneNumberId
          in: query
          schema:
            type: string
        - name: status
          in: query
          schema:
            type: string
            enum:
              - PENDING
              - STORED
              - FAILED
              - DELETING
              - DELETED
        - $ref: "#/components/parameters/page"
        - $ref: "#/components/parameters/limit"
      responses:
        "200":
          description: Page
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - meta
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/MediaAsset"
                  meta:
                    $ref: "#/components/schemas/PageMeta"
  /api/v1/media/assets/{id}:
    get:
      tags:
        - Media
      summary: Get a stored copy with a fresh signed URL
      operationId: getMediaAsset
      parameters:
        - $ref: "#/components/parameters/id"
      responses:
        "200":
          description: Asset
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/MediaAsset"
        "404":
          $ref: "#/components/responses/Error"
    delete:
      tags:
        - Media
      summary: Delete the stored copy now
      operationId: deleteMediaAsset
      parameters:
        - $ref: "#/components/parameters/id"
      responses:
        "204":
          description: Deleted
  /api/v1/media/assets/{id}/content:
    get:
      tags:
        - Media
      summary: Redirect to a 5-minute signed URL
      operationId: getMediaAssetContent
      parameters:
        - $ref: "#/components/parameters/id"
      responses:
        "302":
          description: Location is the signed URL
        "404":
          $ref: "#/components/responses/Error"
  /api/v1/media/assets/{id}/retry:
    post:
      tags:
        - Media
      summary: Queue a failed copy again
      operationId: retryMediaAsset
      parameters:
        - $ref: "#/components/parameters/id"
      responses:
        "202":
          description: Queued
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: "#/components/schemas/MediaAsset"
        "400":
          $ref: "#/components/responses/Error"
  /api/v1/usage/media:
    get:
      tags:
        - Usage
      summary: Stored media per phone number
      description: Point-in-time totals of STORED copies, with customerId, for
        rebilling storage.
      operationId: getMediaUsage
      responses:
        "200":
          description: Usage
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      totals:
                        $ref: "#/components/schemas/MediaUsageTotals"
                      byPhoneNumber:
                        type: array
                        items:
                          allOf:
                            - $ref: "#/components/schemas/MediaUsageTotals"
                            - type: object
                              properties:
                                customerId:
                                  type:
                                    - string
                                    - "null"
                                phoneNumberId:
                                  type: string
  /api/v1/usage:
    get:
      tags:
        - Usage
      summary: Tenant usage totals
      description: Not split by customer. Scope usage:read.
      operationId: getUsage
      parameters:
        - $ref: "#/components/parameters/from"
        - $ref: "#/components/parameters/to"
      responses:
        "200":
          description: Totals
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    properties:
                      totalOutbound:
                        type: integer
                      totalInbound:
                        type: integer
                      totalTemplateSent:
                        type: integer
                      totalMediaUpload:
                        type: integer
                      totalMediaDownload:
                        type: integer
  /api/v1/usage/daily:
    get:
      tags:
        - Usage
      summary: Daily usage
      operationId: getUsageDaily
      parameters:
        - $ref: "#/components/parameters/from"
        - $ref: "#/components/parameters/to"
      responses:
        "200":
          description: Rows
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        usageType:
                          type: string
                        quantity:
                          type: integer
  /api/v1/usage/by-phone-number:
    get:
      tags:
        - Usage
      summary: Message counts by phone
      description: |-
        Join phoneNumberId to GET /phone-numbers to read customerId.
        There is no /usage/by-customer.
      operationId: getUsageByPhoneNumber
      parameters:
        - $ref: "#/components/parameters/from"
        - $ref: "#/components/parameters/to"
      responses:
        "200":
          description: Counts
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      required:
                        - phoneNumberId
                        - direction
                        - count
                      properties:
                        phoneNumberId:
                          type: string
                        direction:
                          type: string
                        count:
                          type: integer
  /api/v1/billing/rate-card:
    get:
      tags:
        - Billing
      summary: Active Meta rate-card rows
      description: |-
        Scope billing:read. Local approximate rates. Not an invoice and not
        filtered by customer.
      operationId: getBillingRateCard
      responses:
        "200":
          description: Rate rows
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/RateCardRow"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Tenant API key. Not the dashboard Settings API key.
  parameters:
    id:
      name: id
      in: path
      required: true
      schema:
        type: string
    customerId:
      name: customerId
      in: path
      required: true
      schema:
        type: string
    token:
      name: token
      in: path
      required: true
      schema:
        type: string
    page:
      name: page
      in: query
      schema:
        type: integer
        minimum: 1
        default: 1
    limit:
      name: limit
      in: query
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 50
    search:
      name: search
      in: query
      schema:
        type: string
    from:
      name: from
      in: query
      schema:
        type: string
        format: date-time
    to:
      name: to
      in: query
      schema:
        type: string
        format: date-time
    idempotencyKey:
      name: Idempotency-Key
      in: header
      description: 1-200 printable ASCII characters, no spaces. Unique per tenant.
      schema:
        type: string
        maxLength: 200
  responses:
    Error:
      description: Error envelope
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
  schemas:
    HealthCheck:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum:
            - ok
            - error
        latencyMs:
          type: number
        error:
          type: string
    RateCardRow:
      type: object
      properties:
        id:
          type: string
        category:
          type: string
        countryIso2:
          type: string
        rateMicros:
          type: string
          description: Digit string.
        rateUsd:
          type: string
        effectiveFrom:
          type: string
          format: date-time
        effectiveTo:
          type:
            - string
            - "null"
          format: date-time
        source:
          type: string
    Error:
      type: object
      required:
        - statusCode
        - code
        - message
      properties:
        statusCode:
          type: integer
        code:
          type: string
        message:
          type: string
        details:
          description: |-
            Included when the thrown error has a details property and JSON
            serialization keeps it. Fastify/Zod validation sets an array.
            ValidationError without a second argument omits details.
            Some billing errors include an object.
            META_ERROR includes code, message, and error_user_msg from Graph.
    PageMeta:
      type: object
      properties:
        page:
          type: integer
        limit:
          type: integer
        total:
          type: integer
        totalPages:
          type: integer
    Customer:
      type: object
      required:
        - id
        - tenantId
        - name
      properties:
        id:
          type: string
        tenantId:
          type: string
        name:
          type: string
        externalCustomerId:
          type:
            - string
            - "null"
        metadata:
          type:
            - object
            - "null"
          additionalProperties: true
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      description: These are the schema fields.
    CustomerCreate:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 255
        externalCustomerId:
          type: string
          maxLength: 255
        metadata:
          type: object
          additionalProperties: true
    CustomerUpdate:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 255
        externalCustomerId:
          type:
            - string
            - "null"
          maxLength: 255
        metadata:
          type:
            - object
            - "null"
          additionalProperties: true
    CustomerPage:
      type: object
      required:
        - data
        - meta
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Customer"
        meta:
          $ref: "#/components/schemas/PageMeta"
    SetupLinkStatus:
      type: string
      enum:
        - ACTIVE
        - IN_PROGRESS
        - USED
        - EXPIRED
        - REVOKED
    WhatsappSetupStatus:
      type: string
      enum:
        - PENDING
        - PROCESSING
        - COMPLETED
        - FAILED
    SetupLink:
      type: object
      description: Stored row returned by list and get. tokenHash is included. It is
        not the raw token.
      properties:
        id:
          type: string
        tenantId:
          type: string
        customerId:
          type: string
        tokenHash:
          type: string
          description: HMAC of the raw token. Not usable as the setup URL token.
        status:
          $ref: "#/components/schemas/SetupLinkStatus"
        expiresAt:
          type: string
          format: date-time
        language:
          type:
            - string
            - "null"
          description: Null means automatic (Accept-Language, then English).
        successRedirectUrl:
          type:
            - string
            - "null"
        failureRedirectUrl:
          type:
            - string
            - "null"
        allowedConnectionTypes:
          type: array
          items:
            type: string
            enum:
              - coexistence
              - dedicated
        connectionType:
          type:
            - string
            - "null"
          enum:
            - coexistence
            - dedicated
            - null
        whatsappSetupStatus:
          $ref: "#/components/schemas/WhatsappSetupStatus"
        whatsappSetupError:
          type:
            - string
            - "null"
        phoneNumberId:
          type:
            - string
            - "null"
        brandingProfileId:
          type:
            - string
            - "null"
        openedAt:
          type:
            - string
            - "null"
          format: date-time
          description: Set when the hosted page is opened or headless config is fetched.
            Null means unopened.
    SetupLinkCreate:
      type: object
      properties:
        brandingProfileId:
          type: string
        language:
          type:
            - string
            - "null"
          maxLength: 10
          description: Omit or null to follow Accept-Language. es, pt, or en forces that
            language.
        expiresInDays:
          type: integer
          minimum: 1
          maximum: 30
        setupPageBaseUrl:
          type: string
          format: uri
        successRedirectUrl:
          type:
            - string
            - "null"
          format: uri
        failureRedirectUrl:
          type:
            - string
            - "null"
          format: uri
        allowedConnectionTypes:
          type: array
          minItems: 1
          maxItems: 2
          items:
            type: string
            enum:
              - coexistence
              - dedicated
    SetupLinkPatch:
      type: object
      additionalProperties: false
      properties:
        expiresAt:
          type: string
          format: date-time
          description: Must be in the future and at most 30 days from now. Do not send
            with expiresInDays.
        expiresInDays:
          type: integer
          minimum: 1
          maximum: 30
        language:
          type:
            - string
            - "null"
          maxLength: 10
        successRedirectUrl:
          type:
            - string
            - "null"
          format: uri
        failureRedirectUrl:
          type:
            - string
            - "null"
          format: uri
        brandingProfileId:
          type:
            - string
            - "null"
        allowedConnectionTypes:
          type: array
          minItems: 1
          maxItems: 2
          items:
            type: string
            enum:
              - coexistence
              - dedicated
        status:
          type: string
          enum:
            - REVOKED
    SetupLinkCreated:
      type: object
      required:
        - id
        - token
        - url
      properties:
        id:
          type: string
        token:
          type: string
          description: Shown once.
        url:
          type: string
    Repair:
      type: object
      properties:
        action:
          type: string
          enum:
            - pending
            - needs_reconnect
        reason:
          type: string
          description: Present when action is needs_reconnect.
    Branding:
      type: object
      properties:
        id:
          type: string
        tenantId:
          type: string
        displayName:
          type: string
        logoUrl:
          type:
            - string
            - "null"
        accentColor:
          type: string
        supportEmail:
          type:
            - string
            - "null"
        allowedRedirectUrls:
          description: JSON array of URLs.
    BrandingCreate:
      type: object
      required:
        - displayName
      properties:
        displayName:
          type: string
          maxLength: 255
        logoUrl:
          type: string
          format: uri
        accentColor:
          type: string
          pattern: ^#[0-9a-fA-F]{6}$
        supportEmail:
          type: string
          format: email
        allowedRedirectUrls:
          type: array
          maxItems: 10
          items:
            type: string
            format: uri
    BrandingUpdate:
      type: object
      properties:
        displayName:
          type: string
        logoUrl:
          type:
            - string
            - "null"
        accentColor:
          type: string
        supportEmail:
          type:
            - string
            - "null"
        allowedRedirectUrls:
          type: array
          items:
            type: string
    PublicSetupConfig:
      type: object
      properties:
        token:
          type: string
        setupToken:
          type: string
        status:
          $ref: "#/components/schemas/SetupLinkStatus"
        whatsappSetupStatus:
          $ref: "#/components/schemas/WhatsappSetupStatus"
        whatsappSetupError:
          type:
            - string
            - "null"
        appId:
          type: string
        configId:
          type: string
        graphVersion:
          type: string
        metaAppId:
          type: string
          description: Same value as appId.
        metaConfigId:
          type: string
          description: Same value as configId.
        metaApiVersion:
          type: string
        displayName:
          type: string
        logoUrl:
          type:
            - string
            - "null"
        accentColor:
          type: string
        supportEmail:
          type:
            - string
            - "null"
        language:
          type:
            - string
            - "null"
        locale:
          type: string
          enum:
            - en
            - es
            - pt
          description: Resolved from the link language, then Accept-Language, then en.
        allowedConnectionTypes:
          type: array
          items:
            type: string
            enum:
              - coexistence
              - dedicated
        connectionType:
          type:
            - string
            - "null"
          enum:
            - coexistence
            - dedicated
            - null
    SessionInfo:
      type: object
      properties:
        waba_id:
          type: string
        phone_number_id:
          type: string
        business_id:
          type: string
    PhoneNumberStatus:
      type: string
      enum:
        - ACTIVE
        - INACTIVE
        - BANNED
        - PENDING_VERIFICATION
    PhoneNumber:
      type: object
      description: |-
        Stored row. Use id as phoneNumberId when sending.
        waPhoneNumberId is Meta's id and is what webhooks carry.
      properties:
        id:
          type: string
        tenantId:
          type: string
        customerId:
          type:
            - string
            - "null"
        phoneNumber:
          type: string
        displayName:
          type:
            - string
            - "null"
        waPhoneNumberId:
          type: string
        status:
          $ref: "#/components/schemas/PhoneNumberStatus"
        qualityRating:
          type:
            - string
            - "null"
        maxMessagesPerSecond:
          type: integer
        isVerified:
          type: boolean
        connectionType:
          type:
            - string
            - "null"
          enum:
            - coexistence
            - dedicated
            - null
        lastError:
          type:
            - string
            - "null"
        botPauseMinutesOnEcho:
          type:
            - integer
            - "null"
          minimum: 0
          maximum: 1440
          description: >-
            Minutes to pause tenant bots after a WhatsApp Business app reply.

            Null uses the deployment default of 30. 0 disables the pause for
            this number.
    Conversation:
      type: object
      description: |-
        Stored conversation. Other columns are included. botPaused is derived
        and is true only while humanActiveUntil is in the future. List rows
        also include the contact and group when present.
      properties:
        id:
          type: string
        tenantId:
          type: string
        phoneNumberId:
          type: string
        contactId:
          type:
            - string
            - "null"
        windowExpiresAt:
          type:
            - string
            - "null"
          format: date-time
        lastInboundCustomerMsgAt:
          type:
            - string
            - "null"
          format: date-time
        lastBusinessAppReplyAt:
          type:
            - string
            - "null"
          format: date-time
          description: |-
            Meta timestamp of the last WhatsApp Business app reply that started
            or extended the pause. A late echo, a revoke, or a number with the
            pause disabled does not move it.
        humanActiveUntil:
          type:
            - string
            - "null"
          format: date-time
          description: Pause end. Null after bot-resume clears an active pause. An already
            expired timestamp is left in place.
        botResumedAt:
          type:
            - string
            - "null"
          format: date-time
        botPaused:
          type: boolean
        windowOpen:
          type: boolean
    SendMessage:
      allOf:
        - $ref: "#/components/schemas/SendMessageBody"
        - type: object
          required:
            - phoneNumberId
          properties:
            phoneNumberId:
              type: string
              description: Whitelabel WhatsApp Cloud API phone id, not Meta's waPhoneNumberId.
    SendMessageBody:
      type: object
      required:
        - to
        - type
      properties:
        to:
          type: string
        recipientType:
          type: string
          enum:
            - individual
            - group
          default: individual
        type:
          type: string
          description: template, text, image, video, audio, document, sticker, location,
            contacts, interactive, reaction.
        text:
          type: object
          properties:
            body:
              type: string
            preview_url:
              type: boolean
        template:
          type: object
          required:
            - name
            - language
          properties:
            name:
              type: string
            language:
              type: object
              required:
                - code
              properties:
                code:
                  type: string
            components:
              type: array
              items:
                type: object
                additionalProperties: true
              description: Meta template components. Passed through.
        context:
          type: object
          properties:
            message_id:
              type: string
      additionalProperties: true
      description: image, video, audio, document, sticker, location, contacts,
        interactive, and reaction objects are accepted and passed through. See
        messages.routes.ts.
    Message:
      type: object
      description: Stored row.
      properties:
        id:
          type: string
        tenantId:
          type: string
        phoneNumberId:
          type: string
        direction:
          type: string
          enum:
            - INBOUND
            - OUTBOUND
        type:
          type: string
        status:
          type: string
          enum:
            - PENDING
            - SENT
            - DELIVERED
            - READ
            - FAILED
        wamId:
          type:
            - string
            - "null"
        errorCode:
          type:
            - string
            - "null"
        errorMessage:
          type:
            - string
            - "null"
        pricingCategory:
          type:
            - string
            - "null"
        pricingBillable:
          type:
            - boolean
            - "null"
        metaCostMicros:
          type:
            - string
            - "null"
          description: Digit string. Local rate-card estimate when a status webhook
            included pricing. Not a collected charge in META_DIRECT.
        createdAt:
          type: string
          format: date-time
    MessagePage:
      type: object
      required:
        - data
        - meta
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Message"
        meta:
          $ref: "#/components/schemas/PageMeta"
    Template:
      type: object
      properties:
        id:
          type: string
        tenantId:
          type: string
        wabaId:
          type: string
        name:
          type: string
        language:
          type: string
        category:
          type: string
          enum:
            - MARKETING
            - UTILITY
            - AUTHENTICATION
        status:
          type: string
          enum:
            - PENDING
            - APPROVED
            - REJECTED
            - PAUSED
            - DISABLED
            - IN_APPEAL
        components:
          description: JSON.
        metaId:
          type:
            - string
            - "null"
    TemplateCreate:
      type: object
      required:
        - wabaId
        - name
        - language
        - category
        - components
      properties:
        wabaId:
          type: string
        name:
          type: string
          maxLength: 512
        language:
          type: string
          minLength: 2
          maxLength: 10
        category:
          type: string
          enum:
            - MARKETING
            - UTILITY
            - AUTHENTICATION
        components:
          type: array
          items:
            type: object
            additionalProperties: true
    TemplatePage:
      type: object
      required:
        - data
        - meta
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Template"
        meta:
          $ref: "#/components/schemas/PageMeta"
    ApiKeyPublic:
      type: object
      required:
        - id
        - name
        - keyPrefix
        - scopes
        - createdAt
        - lastUsedAt
        - expiresAt
        - revokedAt
      properties:
        id:
          type: string
        name:
          type: string
        keyPrefix:
          type: string
          description: First 12 characters of the raw key. The raw key starts with `***`.
        scopes:
          type: array
          items:
            type: string
        createdAt:
          type: string
          format: date-time
        lastUsedAt:
          type:
            - string
            - "null"
          format: date-time
        expiresAt:
          type:
            - string
            - "null"
          format: date-time
        revokedAt:
          type:
            - string
            - "null"
          format: date-time
    ApiKeyCreate:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 255
        scopes:
          type: array
          items:
            type: string
          description: Omit to copy the caller’s scopes. A tenant key cannot grant a scope
            it does not have.
        expiresAt:
          type: string
          format: date-time
    WebhookConfig:
      type: object
      properties:
        webhookUrl:
          type:
            - string
            - "null"
        hasSecret:
          type: boolean
        circuitOpen:
          type: boolean
        circuitUntil:
          type:
            - string
            - "null"
          format: date-time
        failCount:
          type: integer
    WebhookDelivery:
      type: object
      properties:
        id:
          type: string
        tenantId:
          type: string
        eventType:
          type: string
        payload:
          type: object
          additionalProperties: true
        status:
          type: string
          enum:
            - PENDING
            - DELIVERED
            - FAILED
            - DLQ
        attempts:
          type: integer
        maxAttempts:
          type: integer
        lastError:
          type:
            - string
            - "null"
        nextRetryAt:
          type:
            - string
            - "null"
        deliveredAt:
          type:
            - string
            - "null"
        createdAt:
          type: string
    ReplayResult:
      type: object
      required:
        - data
      properties:
        data:
          type: object
          properties:
            replayed:
              type: integer
            ids:
              type: array
              items:
                type: string
    MediaKind:
      type: string
      enum:
        - image
        - video
        - audio
        - document
        - sticker
    UploadedMedia:
      type: object
      required:
        - mediaId
        - mimeType
        - byteSize
        - sha256
        - kind
      properties:
        mediaId:
          type: string
          description: Meta media id for the send body.
        mimeType:
          type: string
        byteSize:
          type: integer
        sha256:
          type: string
        filename:
          type:
            - string
            - "null"
        kind:
          $ref: "#/components/schemas/MediaKind"
    MediaAsset:
      type: object
      description: Also the `data` of message.media_ready and message.media_failed
        (plus wamId, conversationId, origin).
      properties:
        mediaAssetId:
          type: string
        messageId:
          type:
            - string
            - "null"
        phoneNumberId:
          type: string
        direction:
          type: string
          enum:
            - INBOUND
            - OUTBOUND
        kind:
          $ref: "#/components/schemas/MediaKind"
        status:
          type: string
          enum:
            - PENDING
            - STORED
            - FAILED
            - DELETING
            - DELETED
        waMediaId:
          type:
            - string
            - "null"
        mimeType:
          type:
            - string
            - "null"
        byteSize:
          type:
            - integer
            - "null"
        sha256:
          type:
            - string
            - "null"
        filename:
          type:
            - string
            - "null"
        caption:
          type:
            - string
            - "null"
        transcript:
          oneOf:
            - type: "null"
            - type: object
              properties:
                text:
                  type: string
                language:
                  type:
                    - string
                    - "null"
                provider:
                  type:
                    - string
                    - "null"
        url:
          type:
            - string
            - "null"
          description: Signed, time-limited. Present on single reads and media_ready.
        urlExpiresAt:
          type:
            - string
            - "null"
          format: date-time
        storedAt:
          type:
            - string
            - "null"
          format: date-time
        expiresAt:
          type:
            - string
            - "null"
          format: date-time
          description: When retention deletes the copy. null = kept.
        error:
          type:
            - string
            - "null"
        createdAt:
          type: string
          format: date-time
    MediaUsageTotals:
      type: object
      properties:
        storedFiles:
          type: integer
        storedBytes:
          type: integer
        transcribedFiles:
          type: integer
