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

# Criar modelo de mensagem

> Cria um modelo interno ou um modelo oficial de campanha na Meta.



## OpenAPI

````yaml /openapi/gateway.json post /v1/message-templates
openapi: 3.0.0
info:
  title: Spark
  description: >-
    Documentação da API pública do Spark CRM. Respostas de erro usam `{
    statusCode, code, message }`; trate erros pelo campo `code` (veja catálogo
    completo abaixo).


    ## Erros da API


    Todas as respostas de erro seguem o formato `{ statusCode, code, message }`.

    O campo **`code`** é estável entre versões — trate erros pelo código, não
    pela mensagem.


    | Código | HTTP | Descrição |

    | --- | ---: | --- |

    | `API_KEY_MISSING` | 401 | Cabeçalho `X-API-Key` ausente. Inclua a chave em
    todas as requisições autenticadas. |

    | `API_KEY_INVALID` | 401 | Prefixo ou valor da API Key não reconhecido.
    Verifique se copiou a chave correta do painel. |

    | `API_KEY_WRONG_TYPE` | 401 | O tipo da chave (pública ou privada) não é
    aceito neste endpoint. |

    | `DEVELOPERS_DISABLED` | 401 | Habilite o ambiente de desenvolvedores no
    painel antes de usar a API. |

    | `SUBSCRIPTION_INACTIVE` | 403 | O tenant não possui plano ativo ou a
    assinatura está suspensa/cancelada. |

    | `LEAD_LIMIT_EXCEEDED` | 403 | A operação criaria leads além do limite do
    plano atual. Faça upgrade ou remova leads. |

    | `FORM_INACTIVE` | 403 | O formulário existe, mas está desativado e não
    pode ser exibido nem receber envios. |

    | `RESOURCE_ACCESS_DENIED` | 403 | O recurso pertence a outro tenant ou a
    chave não tem escopo para lê-lo. |

    | `ENTRYPOINT_NOT_FOUND` | 404 | Nenhum entrypoint com o ID informado foi
    encontrado para o tenant autenticado. |

    | `FORM_NOT_FOUND` | 404 | Nenhum formulário com o ID público informado foi
    encontrado para o tenant autenticado. |

    | `CHAT_NOT_FOUND` | 404 | Nenhum chat com o ID informado foi encontrado
    para o tenant autenticado. |

    | `RESOURCE_NOT_FOUND` | 404 | O recurso solicitado não existe ou não está
    acessível para o tenant autenticado. |

    | `FORM_ALREADY_SUBMITTED` | 409 | Cada telefone pode enviar apenas uma
    resposta por formulário. |

    | `VALIDATION_ERROR` | 400 | Corpo, query ou parâmetros não passaram na
    validação de schema. |

    | `INVALID_PHONE` | 400 | O telefone informado não pôde ser normalizado para
    E.164. |

    | `ENTRYPOINT_PLATFORM_UNSUPPORTED` | 400 | O entrypoint informado pertence
    a uma plataforma não suportada pela operação. |

    | `PLATFORM_UNSUPPORTED` | 400 | Valor de filtro `platform` inválido ou não
    suportado. |

    | `FORM_MISSING_ENTRYPOINTS` | 400 | O formulário não possui entrypoints de
    destino configurados para receber leads. |

    | `FORM_INVALID_ANSWERS` | 400 | Perguntas ausentes, duplicadas,
    desconhecidas ou com opções inválidas. |

    | `FORM_INVALID_DESTINATION` | 400 | Um ou mais entrypoints configurados no
    formulário são inválidos ou inacessíveis. |

    | `MEDIA_UPLOAD_EMPTY` | 400 | O upload multipart não incluiu nenhum
    arquivo. |

    | `MEDIA_UPLOAD_TOO_MANY_FILES` | 400 | Mais arquivos foram enviados do que
    o permitido por requisição. |

    | `MEDIA_FILE_TOO_LARGE` | 400 | Um ou mais arquivos ultrapassam o limite de
    tamanho. |

    | `MEDIA_INVALID_FORMAT` | 400 | O tipo MIME ou conteúdo do arquivo não é
    aceito para upload de mídia. |

    | `INVALID_REQUEST` | 400 | A combinação de campos ou parâmetros da
    requisição não é permitida. |

    | `UNPROCESSABLE_REQUEST` | 422 | A requisição está bem formada, mas não
    pode ser processada no estado atual. |

    | `MESSAGE_CAMPAIGN_NOT_ALLOWED` | 422 | O corpo da mensagem referencia
    campanha, o que não é permitido na API pública. |

    | `CAMPAIGN_NOT_FOUND` | 404 | Nenhuma campanha com o ID informado foi
    encontrada para o tenant autenticado. |

    | `CAMPAIGN_NAME_ALREADY_EXISTS` | 400 | O nome da campanha deve ser único
    dentro da organização. |

    | `CAMPAIGN_TEMPLATE_NOT_FOUND` | 404 | O templateId informado não existe ou
    não pertence ao tenant autenticado. |

    | `CAMPAIGN_TEMPLATE_PLATFORM_MISMATCH` | 400 | Templates oficiais só podem
    ser usados em WhatsApp Business ou Instagram. |

    | `CAMPAIGN_INVALID_FILTERS` | 422 | Um ou mais filtros possuem campo,
    operador ou valor incompatível. |

    | `CAMPAIGN_NOT_DRAFT` | 422 | A campanha já foi iniciada, concluída ou
    cancelada. |

    | `CAMPAIGN_ALREADY_PROCESSING` | 422 | Aguarde a conclusão ou cancele a
    execução atual antes de iniciar novamente. |

    | `CAMPAIGN_MISSING_COMMON_VARIABLES` | 400 | Informe commonVariables com as
    chaves var1, var2, etc. exigidas pelo template. |

    | `CAMPAIGN_SIZE_LIMIT_EXCEEDED` | 422 | Reduza o público-alvo ou ajuste os
    filtros antes de iniciar. |

    | `MESSAGE_TEMPLATE_NOT_FOUND` | 404 | Nenhum modelo de mensagem com o ID
    informado foi encontrado. |

    | `RATE_LIMIT_EXCEEDED` | 429 | Muitas requisições em curto intervalo.
    Aguarde e tente novamente. |

    | `INTERNAL_ERROR` | 500 | Falha inesperada no servidor. Se persistir,
    contate o suporte. |


    Schema:
    [`PublicApiErrorResponse`](#/components/schemas/PublicApiErrorResponse).
  version: '1.0'
  contact: {}
servers:
  - url: https://gateway.crmspark.com.br
    description: Oficial
security: []
tags: []
paths:
  /v1/message-templates:
    post:
      tags:
        - Message Templates
      summary: Criar modelo de mensagem
      description: Cria um modelo interno ou um modelo oficial de campanha na Meta.
      operationId: messagetemplates_create_v1
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMessageTemplateBodySchema'
      responses:
        '201':
          description: Modelo criado.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetMessageTemplateResponseSchema'
        '400':
          description: >-
            - `MESSAGE_TEMPLATE_META_ERROR` (400): A Meta recusou criar, editar
            ou excluir o modelo.

            - `VALIDATION_ERROR` (400): O conteúdo não segue as regras de modelo
            de campanha.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                MESSAGE_TEMPLATE_META_ERROR:
                  value:
                    statusCode: 400
                    code: MESSAGE_TEMPLATE_META_ERROR
                    message: Erro ao criar template na Meta.
                VALIDATION_ERROR:
                  value:
                    statusCode: 400
                    code: VALIDATION_ERROR
                    message: O corpo do modelo é obrigatório.
        '401':
          description: >-
            - `API_KEY_MISSING` (401): Cabeçalho `X-API-Key` ausente. Inclua a
            chave em todas as requisições autenticadas.

            - `API_KEY_INVALID` (401): Prefixo ou valor da API Key não
            reconhecido. Verifique se copiou a chave correta do painel.

            - `API_KEY_WRONG_TYPE` (401): O tipo da chave (pública ou privada)
            não é aceito neste endpoint.

            - `DEVELOPERS_DISABLED` (401): Habilite o ambiente de
            desenvolvedores no painel antes de usar a API.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                API_KEY_MISSING:
                  value:
                    statusCode: 401
                    code: API_KEY_MISSING
                    message: API Key não fornecida.
                API_KEY_INVALID:
                  value:
                    statusCode: 401
                    code: API_KEY_INVALID
                    message: API Key inválida.
                API_KEY_WRONG_TYPE:
                  value:
                    statusCode: 401
                    code: API_KEY_WRONG_TYPE
                    message: API Key não autorizada a acessar este recurso.
                DEVELOPERS_DISABLED:
                  value:
                    statusCode: 401
                    code: DEVELOPERS_DISABLED
                    message: >-
                      O ambiente de desenvolvedores não está habilitado para
                      este tenant.
        '403':
          description: >-
            - `SUBSCRIPTION_INACTIVE` (403): O tenant não possui plano ativo ou
            a assinatura está suspensa/cancelada.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                SUBSCRIPTION_INACTIVE:
                  value:
                    statusCode: 403
                    code: SUBSCRIPTION_INACTIVE
                    message: Sua organização não possui uma assinatura ativa.
        '409':
          description: >-
            - `MESSAGE_TEMPLATE_META_NAME_TAKEN` (409): Já existe um modelo
            oficial com esse nome e idioma.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                MESSAGE_TEMPLATE_META_NAME_TAKEN:
                  value:
                    statusCode: 409
                    code: MESSAGE_TEMPLATE_META_NAME_TAKEN
                    message: Já existe um modelo oficial com esse nome e idioma.
        '429':
          description: >-
            - `RATE_LIMIT_EXCEEDED` (429): Muitas requisições em curto
            intervalo. Aguarde e tente novamente.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                RATE_LIMIT_EXCEEDED:
                  value:
                    statusCode: 429
                    code: RATE_LIMIT_EXCEEDED
                    message: Limite de requisições excedido.
      security:
        - api-key: []
components:
  schemas:
    CreateMessageTemplateBodySchema:
      oneOf:
        - type: object
          properties:
            name:
              type: string
            description:
              type: string
              nullable: true
            isOfficial:
              type: boolean
              enum:
                - true
            whatsappEntrypointId:
              type: string
            metaTemplateName:
              type: string
              pattern: ^[a-z0-9_]+$
              maxLength: 512
            category:
              type: string
              enum:
                - MARKETING
                - UTILITY
            language:
              type: string
            header:
              oneOf:
                - type: object
                  properties:
                    format:
                      type: string
                      enum:
                        - TEXT
                    text:
                      type: string
                      maxLength: 60
                  required:
                    - format
                    - text
                - type: object
                  properties:
                    format:
                      type: string
                      enum:
                        - IMAGE
                        - VIDEO
                        - DOCUMENT
                    mediaId:
                      type: string
                  required:
                    - format
                    - mediaId
            body:
              type: string
              maxLength: 1024
            footer:
              type: string
              maxLength: 60
            buttons:
              type: array
              maxItems: 10
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - QUICK_REPLY
                      - URL
                      - PHONE_NUMBER
                  text:
                    type: string
                    maxLength: 25
                  url:
                    type: string
                    maxLength: 2000
                  phone_number:
                    type: string
                required:
                  - type
                  - text
            variables:
              type: array
              items:
                type: object
                properties:
                  index:
                    type: integer
                    minimum: 1
                  title:
                    type: string
                  example:
                    type: string
                    maxLength: 15
                  kind:
                    type: string
                    enum:
                      - common
                      - lead
                  source:
                    type: string
                required:
                  - index
                  - title
                  - example
                  - kind
          required:
            - name
            - isOfficial
            - whatsappEntrypointId
            - metaTemplateName
            - category
            - language
            - body
        - type: object
          properties:
            name:
              type: string
            description:
              type: string
              nullable: true
            isOfficial:
              type: boolean
              enum:
                - false
            items:
              type: array
              minItems: 1
              items:
                type: object
                properties:
                  order:
                    type: integer
                    minimum: 0
                  type:
                    type: string
                    enum:
                      - text
                      - image
                      - audio
                      - video
                      - document
                  text:
                    type: string
                    nullable: true
                  mediaId:
                    type: string
                    nullable: true
                required:
                  - order
                  - type
            variables:
              type: array
              items:
                type: object
                properties:
                  index:
                    type: integer
                    minimum: 1
                  title:
                    type: string
                  example:
                    type: string
                    maxLength: 15
                  kind:
                    type: string
                    enum:
                      - common
                      - lead
                  source:
                    type: string
                required:
                  - index
                  - title
                  - example
                  - kind
          required:
            - name
            - isOfficial
            - items
    GetMessageTemplateResponseSchema:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
          nullable: true
        isOfficial:
          type: boolean
        metaTemplateStatus:
          type: string
          nullable: true
        items:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              order:
                type: number
              type:
                type: string
              text:
                type: string
                nullable: true
              mediaId:
                type: string
                nullable: true
            required:
              - id
              - order
              - type
              - text
              - mediaId
        commonVariables:
          type: array
          items:
            type: object
            properties:
              key:
                type: string
                description: 'Chave da variável (ex.: var1, var2).'
              label:
                type: string
              required:
                type: boolean
            required:
              - key
          description: >-
            Variáveis manuais que devem ser informadas em commonVariables ao
            iniciar uma campanha.
        createdAt:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
        updatedAt:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
        metaTemplateName:
          type: string
          nullable: true
        category:
          type: string
          nullable: true
        language:
          type: string
          nullable: true
        metaRejectedReason:
          type: string
          nullable: true
        body:
          type: string
          nullable: true
        footer:
          type: string
          nullable: true
        header:
          nullable: true
          oneOf:
            - type: object
              properties:
                format:
                  type: string
                  enum:
                    - TEXT
                text:
                  type: string
                  maxLength: 60
              required:
                - format
                - text
            - type: object
              properties:
                format:
                  type: string
                  enum:
                    - IMAGE
                    - VIDEO
                    - DOCUMENT
                mediaId:
                  type: string
              required:
                - format
                - mediaId
        buttons:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - QUICK_REPLY
                  - URL
                  - PHONE_NUMBER
              text:
                type: string
                maxLength: 25
              url:
                type: string
                maxLength: 2000
              phone_number:
                type: string
            required:
              - type
              - text
        variables:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
                minimum: 1
              title:
                type: string
              example:
                type: string
                maxLength: 15
              kind:
                type: string
                enum:
                  - common
                  - lead
              source:
                type: string
            required:
              - index
              - title
              - example
              - kind
      required:
        - id
        - name
        - description
        - isOfficial
        - metaTemplateStatus
        - items
        - commonVariables
        - createdAt
        - updatedAt
        - metaTemplateName
        - category
        - language
        - metaRejectedReason
        - header
        - body
        - footer
        - buttons
        - variables
    PublicApiErrorResponse:
      type: object
      required:
        - statusCode
        - code
        - message
      properties:
        statusCode:
          type: integer
          description: Código HTTP da resposta.
          example: 400
        code:
          type: string
          description: >-
            Código estável e legível por máquina. Use este campo — não parseie
            `message` — para tratar erros no cliente.
          enum:
            - API_KEY_MISSING
            - API_KEY_INVALID
            - API_KEY_WRONG_TYPE
            - DEVELOPERS_DISABLED
            - SUBSCRIPTION_INACTIVE
            - LEAD_LIMIT_EXCEEDED
            - FORM_INACTIVE
            - RESOURCE_ACCESS_DENIED
            - ENTRYPOINT_NOT_FOUND
            - FORM_NOT_FOUND
            - CHAT_NOT_FOUND
            - RESOURCE_NOT_FOUND
            - FORM_ALREADY_SUBMITTED
            - VALIDATION_ERROR
            - INVALID_PHONE
            - ENTRYPOINT_PLATFORM_UNSUPPORTED
            - PLATFORM_UNSUPPORTED
            - FORM_MISSING_ENTRYPOINTS
            - FORM_INVALID_ANSWERS
            - FORM_INVALID_DESTINATION
            - MEDIA_UPLOAD_EMPTY
            - MEDIA_UPLOAD_TOO_MANY_FILES
            - MEDIA_FILE_TOO_LARGE
            - MEDIA_INVALID_FORMAT
            - INVALID_REQUEST
            - UNPROCESSABLE_REQUEST
            - MESSAGE_CAMPAIGN_NOT_ALLOWED
            - CAMPAIGN_NOT_FOUND
            - CAMPAIGN_NAME_ALREADY_EXISTS
            - CAMPAIGN_TEMPLATE_NOT_FOUND
            - CAMPAIGN_TEMPLATE_PLATFORM_MISMATCH
            - CAMPAIGN_INVALID_FILTERS
            - CAMPAIGN_NOT_DRAFT
            - CAMPAIGN_ALREADY_PROCESSING
            - CAMPAIGN_MISSING_COMMON_VARIABLES
            - CAMPAIGN_SIZE_LIMIT_EXCEEDED
            - MESSAGE_TEMPLATE_NOT_FOUND
            - RATE_LIMIT_EXCEEDED
            - INTERNAL_ERROR
        message:
          type: string
          description: Mensagem legível em português, útil para logs e exibição ao usuário.
  securitySchemes:
    api-key:
      type: apiKey
      in: header
      name: X-API-Key

````

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