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

# Create template

> Creates a template and sends it to WhatsApp for approval. The provider decides on approval, in its own time. Follow it through the `template.*` events or by retrieving the template.

Only `approved` templates can be used in `POST /v1/messages`. See [Templates](/en/concepts/templates).

**Every variable needs an example**, which WhatsApp reads when it reviews the template: `variable_examples` for the body, `components.header.example` for the variable of a text header and `components.buttons[].example` for each URL button with a variable (only the value that replaces `{{1}}`). No recipient receives the examples, but they are stored, returned by the API and sent in events and webhooks: **do not use real personal data or tokens**.

Routa refuses **right away**, with `422`, what WhatsApp is already known to refuse. The error then points at the right field, instead of leaving you with a `failed` template minutes later. The `error.param` field says which part of the request failed.

| Rule | Error and `error.param` |
| --- | --- |
| The name uses only `a-z`, `0-9` and `_`, up to 512 characters | `template_name_invalid`, `name` |
| The body has up to 1024 characters | `template_components_invalid`, `body_text` |
| Variables are numbered in sequence starting at `{{1}}` | `template_variables_invalid` |
| The body does not start or end with a `{{n}}` variable | `template_variables_invalid` |
| The text header has up to 60 characters and one variable | `template_components_invalid`, `components.header` |
| The footer has up to 60 characters | `template_components_invalid`, `components.footer` |
| At most 10 buttons, 1 phone button and 2 URL buttons | `template_components_invalid`, `components.buttons` |
| Quick reply buttons stay together, with no other button between them | `template_components_invalid`, `components.buttons` |
| Button text has up to 25 characters, the URL up to 2000 and the phone number up to 20 | `template_components_invalid`, `components.buttons` |
| The `{{1}}` variable of a URL goes at its end, and the URL does not point to `api.whatsapp.com` | `template_components_invalid`, `components.buttons` |
| An `authentication` template takes no buttons of its own | `template_components_invalid`, `components.buttons` |
| Every body variable has an example | `template_variables_invalid`, `variable_examples` or `variable_examples.<position>` |
| The header variable and the variable of each URL button have an example, and whatever has no variable takes no example | `template_variables_invalid`, `components.header.example` or `components.buttons.<position>.example` |

WhatsApp decides on approval. A rule Routa does not check can still lead to `rejected` or `failed`.



## OpenAPI

````yaml en/openapi.json POST /v1/templates
openapi: 3.0.3
info:
  title: Routa API
  description: >-
    REST API to send and receive WhatsApp messages, track delivery and receive
    normalized events through webhooks.
  version: '1'
servers:
  - url: https://api.routa.chat
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Messages
    description: Send, retrieve and list messages.
  - name: Events
    description: Query the log of normalized events.
  - name: Webhooks
    description: Manage webhook endpoints, secrets and deliveries.
  - name: Templates
    description: Create and retrieve WhatsApp templates.
  - name: Media
    description: Upload and download media files.
  - name: Usage
    description: Query the metered usage of the project.
  - name: Identity
    description: Identify the API key in use.
  - name: Partners
    description: >-
      Create one project per customer, issue the key of each project, follow the
      channels and receive the events of every customer on a single webhook.
      These routes use a partner key (`rt_partner_...`). See [Partner
      API](/en/partners/overview).
paths:
  /v1/templates:
    post:
      tags:
        - Templates
      summary: Create template
      description: >-
        Creates a template and sends it to WhatsApp for approval. The provider
        decides on approval, in its own time. Follow it through the `template.*`
        events or by retrieving the template.


        Only `approved` templates can be used in `POST /v1/messages`. See
        [Templates](/en/concepts/templates).


        **Every variable needs an example**, which WhatsApp reads when it
        reviews the template: `variable_examples` for the body,
        `components.header.example` for the variable of a text header and
        `components.buttons[].example` for each URL button with a variable (only
        the value that replaces `{{1}}`). No recipient receives the examples,
        but they are stored, returned by the API and sent in events and
        webhooks: **do not use real personal data or tokens**.


        Routa refuses **right away**, with `422`, what WhatsApp is already known
        to refuse. The error then points at the right field, instead of leaving
        you with a `failed` template minutes later. The `error.param` field says
        which part of the request failed.


        | Rule | Error and `error.param` |

        | --- | --- |

        | The name uses only `a-z`, `0-9` and `_`, up to 512 characters |
        `template_name_invalid`, `name` |

        | The body has up to 1024 characters | `template_components_invalid`,
        `body_text` |

        | Variables are numbered in sequence starting at `{{1}}` |
        `template_variables_invalid` |

        | The body does not start or end with a `{{n}}` variable |
        `template_variables_invalid` |

        | The text header has up to 60 characters and one variable |
        `template_components_invalid`, `components.header` |

        | The footer has up to 60 characters | `template_components_invalid`,
        `components.footer` |

        | At most 10 buttons, 1 phone button and 2 URL buttons |
        `template_components_invalid`, `components.buttons` |

        | Quick reply buttons stay together, with no other button between them |
        `template_components_invalid`, `components.buttons` |

        | Button text has up to 25 characters, the URL up to 2000 and the phone
        number up to 20 | `template_components_invalid`, `components.buttons` |

        | The `{{1}}` variable of a URL goes at its end, and the URL does not
        point to `api.whatsapp.com` | `template_components_invalid`,
        `components.buttons` |

        | An `authentication` template takes no buttons of its own |
        `template_components_invalid`, `components.buttons` |

        | Every body variable has an example | `template_variables_invalid`,
        `variable_examples` or `variable_examples.<position>` |

        | The header variable and the variable of each URL button have an
        example, and whatever has no variable takes no example |
        `template_variables_invalid`, `components.header.example` or
        `components.buttons.<position>.example` |


        WhatsApp decides on approval. A rule Routa does not check can still lead
        to `rejected` or `failed`.
      operationId: createTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - channel
                - name
                - language
                - category
                - body_text
              properties:
                channel:
                  description: Channel the template belongs to (`chan_...`).
                  type: string
                  example: chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ
                name:
                  description: >-
                    Template name: only lowercase letters, digits and `_`
                    (`a-z`, `0-9`, `_`), up to 512 characters.
                  type: string
                  example: order_confirmation
                language:
                  description: >-
                    The language of the template, in the code WhatsApp uses,
                    such as `pt_BR`, `en_US` or `en`. The region is joined with
                    an underscore (`en_US`, not `en-US`).
                  type: string
                  example: en_US
                category:
                  type: string
                  enum:
                    - marketing
                    - utility
                    - authentication
                  description: >-
                    Template category: `marketing`, `utility` or
                    `authentication`.
                body_text:
                  description: >-
                    Template body, with positional placeholders `{{1}}`,
                    `{{2}}`, …, up to 1024 characters. It cannot start or end
                    with a variable.
                  type: string
                  example: Hi {{1}}! Your order {{2}} is confirmed.
                variable_examples:
                  description: >-
                    One example for each variable of `body_text`, the first one
                    for `{{1}}`: the order of the numbers counts, not the order
                    in the text. **Required when the body has a variable**, with
                    exactly one item per variable, none empty or blank. Do not
                    use real personal data or tokens.
                  type: array
                  items:
                    type: string
                  example:
                    - Ana
                    - '1234'
                components:
                  description: >-
                    Optional components: a text or media header, a footer and up
                    to 10 buttons. Omit the field for a text-only template.
                  type: object
                  properties:
                    header:
                      oneOf:
                        - type: object
                          required:
                            - kind
                            - text
                          properties:
                            kind:
                              type: string
                              enum:
                                - text
                              description: Use `text` for a text header.
                            text:
                              description: >-
                                Header text, up to 60 characters and at most one
                                `{{1}}` variable.
                              type: string
                            example:
                              description: >-
                                Example of the header `{{1}}`. **Required when
                                the text has the variable**. Refused when it
                                does not, and when empty or blank.
                              type: string
                        - type: object
                          required:
                            - kind
                            - media_id
                          properties:
                            kind:
                              type: string
                              enum:
                                - media
                              description: Use `media` for a media header.
                            media_id:
                              description: >-
                                ID (`tmedia_...`) of the file uploaded
                                beforehand with `POST /v1/templates/media`.
                              type: string
                            example:
                              description: >-
                                Refused here: a media header has no variable
                                (`422 template_variables_invalid`).
                              type: string
                      description: >-
                        Text header (up to 60 characters and one variable) or
                        media header (a `media_id` from `POST
                        /v1/templates/media`).
                    footer:
                      type: object
                      required:
                        - text
                      properties:
                        text:
                          description: Footer text, up to 60 characters.
                          type: string
                      description: Text footer, up to 60 characters.
                    buttons:
                      description: >-
                        Up to 10 buttons: at most 1 `phone_number` and 2 `url`.
                        The `quick_reply` buttons stay together, before or after
                        the others. Each button text has up to 25 characters.
                        The URL of a `url` button has up to 2000 characters and
                        can have one `{{1}}` variable, only at the end of the
                        URL.
                      type: array
                      items:
                        oneOf:
                          - type: object
                            required:
                              - kind
                              - text
                            properties:
                              kind:
                                type: string
                                enum:
                                  - quick_reply
                                description: Use `quick_reply` for a quick reply button.
                              text:
                                description: Button text, up to 25 characters.
                                type: string
                              example:
                                description: >-
                                  Refused here: this button has no variable
                                  (`422 template_variables_invalid`).
                                type: string
                          - type: object
                            required:
                              - kind
                              - text
                              - phone_number
                            properties:
                              kind:
                                type: string
                                enum:
                                  - phone_number
                                description: >-
                                  Use `phone_number` for a button that calls a
                                  number.
                              text:
                                description: Button text, up to 25 characters.
                                type: string
                              phone_number:
                                description: >-
                                  The number the button calls, up to 20
                                  characters.
                                type: string
                              example:
                                description: >-
                                  Refused here: this button has no variable
                                  (`422 template_variables_invalid`).
                                type: string
                          - type: object
                            required:
                              - kind
                              - text
                              - url
                            properties:
                              kind:
                                type: string
                                enum:
                                  - url
                                description: Use `url` for a button that opens an address.
                              text:
                                description: Button text, up to 25 characters.
                                type: string
                              url:
                                description: >-
                                  Destination URL. It can have a single `{{1}}`
                                  variable, at the end.
                                type: string
                              example:
                                description: >-
                                  Example of what replaces `{{1}}`: **only that
                                  value**, not the whole URL. **Required when
                                  the URL has the variable**. Refused when it
                                  does not, and when empty or blank.
                                type: string
            example:
              channel: chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ
              name: order_confirmation
              language: en_US
              category: utility
              body_text: Hi {{1}}! Your order {{2}} is confirmed.
              variable_examples:
                - Ana
                - '1234'
              components:
                buttons:
                  - kind: url
                    text: Track order
                    url: https://example.com/orders/{{1}}
                    example: '1234'
      responses:
        '201':
          description: Resource created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Template'
        '401':
          description: >-
            The API key is missing, invalid, revoked or expired
            (`api_key_invalid`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: The key lacks the required scope (`insufficient_scope`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >-
            The resource does not exist or belongs to another project
            (`channel_not_found`, `template_media_not_found`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: >-
            Invalid request (`request_invalid`, `capability_unsupported`,
            `template_name_invalid`, `template_variables_invalid`,
            `template_components_invalid`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded. See the `Retry-After` header
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth:
            - templates:write
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |-
            curl --request POST https://api.routa.chat/v1/templates \
              --header "Authorization: Bearer $ROUTA_API_KEY" \
              --header "Content-Type: application/json" \
              --data '{
              "channel": "chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
              "name": "order_confirmation",
              "language": "en_US",
              "category": "utility",
              "body_text": "Hi {{1}}! Your order {{2}} is confirmed.",
              "variable_examples": [
                "Ana",
                "1234"
              ],
              "components": {
                "buttons": [
                  {
                    "kind": "url",
                    "text": "Track order",
                    "url": "https://example.com/orders/{{1}}",
                    "example": "1234"
                  }
                ]
              }
            }'
        - lang: typescript
          label: Node.js
          source: |-
            import { Routa } from '@routa-chat/sdk'

            const routa = new Routa({ apiKey: process.env['ROUTA_API_KEY']! })

            const template = await routa.templates.submit({
              channel: 'chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ',
              name: 'order_confirmation',
              language: 'en_US',
              category: 'utility',
              bodyText: 'Hi {{1}}! Your order {{2}} is confirmed.',
              variableExamples: ['Ana', '1234'],
              components: {
                buttons: [
                  { kind: 'url', text: 'Track order', url: 'https://example.com/orders/{{1}}', example: '1234' },
                ],
              },
            })
components:
  schemas:
    Template:
      type: object
      properties:
        id:
          type: string
          description: Template ID.
          example: tmpl_01J8ZK9M3Q7XABCDEFGHJKMNPQ
        channel:
          type: string
          description: Channel the template belongs to.
          example: chan_01J8ZK9M3Q7XABCDEFGHJKMNPQ
        name:
          type: string
          description: Template name.
          example: order_confirmation
        language:
          type: string
          description: The WhatsApp language code, such as `pt_BR` or `en_US`.
          example: en_US
        category:
          type: string
          enum:
            - marketing
            - utility
            - authentication
          description: 'Category: `marketing`, `utility` or `authentication`.'
        body_text:
          type: string
          nullable: true
          description: >-
            The template body, with the `{{1}}`, `{{2}}`, … placeholders. It is
            `null` only on an imported, read-only template (`read_only`), which
            Routa cannot reproduce.
          example: Hi {{1}}! Your order {{2}} is confirmed.
        variables:
          type: array
          items:
            type: object
            required:
              - index
            properties:
              index:
                type: number
                description: The number of the variable, starting at 1.
                example: 1
              example:
                type: string
                description: >-
                  The example written for the variable. Absent when the template
                  has none for it, such as an imported template or one created
                  before examples were required.
                example: Ana
          description: Positional placeholders of the body (`{{1}}`, `{{2}}`, …).
        components:
          type: object
          properties:
            header:
              oneOf:
                - type: object
                  required:
                    - kind
                    - text
                  properties:
                    kind:
                      type: string
                      enum:
                        - text
                      description: Always `text` on a text header.
                    text:
                      type: string
                      description: Header text.
                    example:
                      type: string
                      description: >-
                        The example of the header variable. Absent when there is
                        no variable or no example.
                - type: object
                  required:
                    - kind
                    - format
                    - media_id
                  properties:
                    kind:
                      type: string
                      enum:
                        - media
                      description: Always `media` on a media header.
                    format:
                      type: string
                      enum:
                        - image
                        - video
                        - document
                      description: 'Media format: `image`, `video` or `document`.'
                    media_id:
                      type: string
                      description: ID (`tmedia_...`) of the header sample file.
              description: >-
                Template header: text (`kind: text`) or media (`kind: media`).
                Absent when the template has no header.
            footer:
              type: object
              required:
                - text
              properties:
                text:
                  type: string
                  description: Footer text.
              description: Template footer. Absent when the template has none.
            buttons:
              type: array
              items:
                oneOf:
                  - type: object
                    required:
                      - kind
                      - text
                    properties:
                      kind:
                        type: string
                        enum:
                          - quick_reply
                        description: 'Always `quick_reply`: a quick reply button.'
                      text:
                        type: string
                        description: Button text.
                  - type: object
                    required:
                      - kind
                      - text
                      - phone_number
                    properties:
                      kind:
                        type: string
                        enum:
                          - phone_number
                        description: 'Always `phone_number`: a button that calls a number.'
                      text:
                        type: string
                        description: Button text.
                      phone_number:
                        type: string
                        description: The number the button calls.
                  - type: object
                    required:
                      - kind
                      - text
                      - url
                    properties:
                      kind:
                        type: string
                        enum:
                          - url
                        description: 'Always `url`: a button that opens an address.'
                      text:
                        type: string
                        description: Button text.
                      url:
                        type: string
                        description: >-
                          Address the button opens. It can have the `{{1}}`
                          variable, at the end.
                      example:
                        type: string
                        description: >-
                          The example of the URL's `{{1}}`. Absent when there is
                          no variable or no example.
              description: Template buttons, in order. Absent when the template has none.
          description: >-
            Header, footer and buttons of the template. The field is omitted,
            not empty, on a body-only template.
        status:
          type: string
          enum:
            - draft
            - submitted
            - pending
            - approved
            - rejected
            - paused
            - disabled
            - failed
          description: >-
            Approval state. Only `approved` allows sending. `rejected` means the
            provider reviewed the template and refused it. `failed` means Routa
            could not send it to the provider. A `failed` or `rejected` template
            can be edited and sent again in the dashboard, and then goes back to
            `submitted`.
        rejection_reason:
          type: string
          enum:
            - abusive_content
            - incorrect_category
            - invalid_format
            - scam
            - tag_content_mismatch
            - other
          nullable: true
          description: Reason for the rejection, when `status` is `rejected`.
        failure_code:
          type: string
          enum:
            - provider_unavailable
            - provider_auth_failed
            - provider_rejected_request
            - channel_unavailable
            - media_unavailable
            - attempts_exhausted
          nullable: true
          description: >-
            Why it could not be sent for approval, when `status` is `failed`.
            `null` in every other status.
          example: null
        failure_detail:
          type: string
          nullable: true
          description: >-
            Only when `status` is `failed` and the provider explained why: its
            own sentence, written for a person and often in the language of the
            account. It is informational text. Never compare against it; use
            `failure_code`. `null` otherwise.
          example: null
        deletion_requested:
          type: boolean
          description: >-
            `true` from the moment a deletion is accepted (made in the
            dashboard) until Routa finishes deleting the template on WhatsApp.
            In between, the template cannot be used to send, and a message that
            cites it returns `422 template_not_sendable`. `false` otherwise.
          example: false
        deletion_failure_detail:
          type: string
          nullable: true
          description: >-
            Why the last deletion ended without deleting the template, in the
            provider's own sentence when it gave one. It is informational text.
            `null` when no deletion failed.
          example: null
        origin:
          type: string
          enum:
            - routa
            - provider
          description: >-
            Who created the template: `routa` for a template created by Routa,
            `provider` for one that already existed on WhatsApp and was
            imported.
          example: routa
        read_only:
          type: boolean
          description: >-
            `true` for an imported template that Routa cannot reproduce. Sending
            a message with it returns `422 template_not_sendable`. Always
            `false` when `origin` is `routa`.
          example: false
        unsupported_components:
          type: array
          items:
            type: string
            enum:
              - named_parameters
              - media_header
              - location_header
              - carousel
              - flow_button
              - otp_button
              - copy_code_button
              - catalog
              - limited_time_offer
              - other
          description: >-
            Components of an imported template that Routa cannot reproduce.
            Empty when `read_only` is `false`.
          example: []
        created_at:
          format: date-time
          type: string
          description: When the template was created.
          example: '2026-09-04T13:22:41.031Z'
        updated_at:
          format: date-time
          type: string
          description: When the template was last updated.
          example: '2026-09-04T13:22:41.031Z'
      required:
        - id
        - channel
        - name
        - language
        - category
        - body_text
        - variables
        - status
        - rejection_reason
        - failure_code
        - failure_detail
        - deletion_requested
        - deletion_failure_detail
        - origin
        - read_only
        - unsupported_components
        - created_at
        - updated_at
    Error:
      type: object
      properties:
        error:
          type: object
          required:
            - type
            - code
            - message
            - request_id
          properties:
            type:
              type: string
              description: >-
                Error category: `invalid_request_error`, `authentication_error`,
                `permission_error`, `not_found_error`, `conflict_error`,
                `rate_limit_error`, `billing_error` or `api_error`.
              example: invalid_request_error
            code:
              type: string
              description: >-
                Stable, machine-readable code. See [Error
                codes](/en/errors/error-codes).
              example: channel_inactive
            message:
              type: string
              description: >-
                Human-readable text, in English. It can change, so do not parse
                it.
              example: Channel chan_01J8... is not active and cannot send messages.
            param:
              type: string
              description: >-
                The request field at fault, when it applies. It is filled in on
                `request_invalid` (the field outside the schema, such as
                `template.button_parameters.0.index`) and on template errors:
                `name` in `template_name_invalid`; `body_text`,
                `components.header`, `components.footer` or `components.buttons`
                in `template_components_invalid`; and `variable_examples`,
                `variable_examples.<position>`, `components.header.example` or
                `components.buttons.<position>.example` when
                `template_variables_invalid` refuses an example.
              example: components.buttons.0.example
            doc_url:
              type: string
              description: Link to the documentation of the code, when available.
            details:
              type: object
              additionalProperties:
                oneOf:
                  - type: string
                  - type: number
              description: >-
                Actionable values, such as `limit`, `used` and `resets_at` in
                `message_quota_exceeded`, or `reason`, which tells apart the
                causes behind one code, in errors such as `invalid_recipient`
                and `template_variables_invalid`. See [Actionable
                details](/en/errors/overview#actionable-details).
            request_id:
              type: string
              description: Request ID. Quote it when you contact support.
              example: req_01J8ZK9M3Q7XABCDEFGHJKMNPQ
          description: Error details.
      required:
        - error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Project API key, in the format `rt_live_...` or `rt_test_...`, sent as
        `Authorization: Bearer <key>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.