> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cogfy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send template message

> Sends an approved WhatsApp template message. This is the only message type that reaches recipients that never messaged the business or whose service window is closed.

When the template contains a FLOW button, the request must include the matching `button` component with `sub_type: flow`.



## OpenAPI

````yaml POST /messages/template
openapi: 3.1.0
info:
  title: Cogfy Messenger Public API
  version: 1.0.0
  description: API for interacting with the Cogfy Messenger platform
servers:
  - url: https://messenger-public-api.cogfy.com
    description: Production server
  - url: http://localhost:3100
    description: Local server
security:
  - ApiKeyAuth: []
paths:
  /messages/template:
    post:
      tags:
        - Messages
      summary: Send template message
      description: >-
        Sends an approved WhatsApp template message. This is the only message
        type that reaches recipients that never messaged the business or whose
        service window is closed.


        When the template contains a FLOW button, the request must include the
        matching `button` component with `sub_type: flow`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                from:
                  type: string
                  minLength: 1
                  description: WhatsApp id of the sender phone number
                to:
                  type: string
                  minLength: 1
                  description: Recipient phone number, digits only, including country code
                template:
                  type: object
                  properties:
                    name:
                      type: string
                      description: Name of the approved WhatsApp template
                    language:
                      type: object
                      properties:
                        code:
                          type: string
                          description: Language code of the template, e.g. `pt_BR`
                      required:
                        - code
                    components:
                      type: array
                      items:
                        type: object
                        properties:
                          type:
                            type: string
                            description: Component type, e.g. `header`, `body` or `button`
                          sub_type:
                            description: Button sub type, e.g. `flow` or `url`
                            type: string
                          index:
                            description: Index of the button, starting at 0
                            type: integer
                            minimum: 0
                            maximum: 2
                          parameters:
                            description: Parameters that fill the component placeholders
                            type: array
                            items: {}
                          cards:
                            description: Cards of a carousel template
                            type: array
                            items:
                              type: object
                              properties:
                                card_index:
                                  type: number
                                components:
                                  type: array
                                  items:
                                    type: object
                                    properties:
                                      type:
                                        type: string
                                        description: >-
                                          Component type, e.g. `header`, `body` or
                                          `button`
                                      sub_type:
                                        description: Button sub type, e.g. `flow` or `url`
                                        type: string
                                      index:
                                        description: Index of the button, starting at 0
                                        type: integer
                                        minimum: 0
                                        maximum: 2
                                      parameters:
                                        description: >-
                                          Parameters that fill the component
                                          placeholders
                                        type: array
                                        items: {}
                                    required:
                                      - type
                              required:
                                - card_index
                        required:
                          - type
                  required:
                    - name
                    - language
              required:
                - from
                - to
                - template
            examples:
              positional:
                summary: Template with positional body parameters
                value:
                  from: '5511999998888'
                  to: '5599888887777'
                  template:
                    name: appointment_reminder
                    language:
                      code: pt_BR
                    components:
                      - type: body
                        parameters:
                          - type: text
                            text: John
      responses:
        '200':
          description: Message sent successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
                    description: Id of the created message
                  contact:
                    type: object
                    properties:
                      waId:
                        anyOf:
                          - type: string
                          - type: 'null'
                        description: WhatsApp id of the recipient
                      waUserId:
                        anyOf:
                          - type: string
                          - type: 'null'
                    required:
                      - waId
                    additionalProperties: false
                required:
                  - id
                  - contact
                additionalProperties: false
        '400':
          description: >-
            Bad request — invalid input data, or the message was rejected by the
            WhatsApp Cloud API (e.g. invalid template)
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: number
                  title:
                    type: string
                  detail:
                    type: string
                  code:
                    description: >-
                      WhatsApp Cloud API error code, present when the request
                      was rejected by Meta (e.g. invalid template, rate limit)
                    type: number
                required:
                  - status
                  - title
                  - detail
                additionalProperties: false
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: number
                  title:
                    type: string
                  detail:
                    type: string
                  code:
                    description: >-
                      WhatsApp Cloud API error code, present when the request
                      was rejected by Meta (e.g. invalid template, rate limit)
                    type: number
                required:
                  - status
                  - title
                  - detail
                additionalProperties: false
        '404':
          description: >-
            Sender phone number not found or not linked to a WhatsApp Business
            Account
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: number
                  title:
                    type: string
                  detail:
                    type: string
                  code:
                    description: >-
                      WhatsApp Cloud API error code, present when the request
                      was rejected by Meta (e.g. invalid template, rate limit)
                    type: number
                required:
                  - status
                  - title
                  - detail
                additionalProperties: false
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: api-key

````