> ## Documentation Index
> Fetch the complete documentation index at: https://onextel-09023014.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a template

> Create a reusable message with variables, an optional attachment and up to 3 buttons.

A template is saved as a `draft`. [Submit it](https://onextel-09023014.mintlify.site/api-reference/truecaller/submit-template.md) before
you send it.

* **Variables:** write `{{name}}` anywhere in the body, in button labels or in button URLs. In a
  campaign each one is filled from the contact list column with the same name. Set
  `variable_defaults` for contacts whose cell is empty, e.g. `{ "name": "there" }`.
* **Styling:** Truecaller renders `*bold*`, `_italic_`, `~strikethrough~`, `` `monospace` `` and
  `[label](https://…)` links.
* **Media and buttons:** see [Rich messages](https://onextel-09023014.mintlify.site/api-reference/truecaller/rich-messages.md).


## OpenAPI

````yaml api-reference/truecaller/openapi.yaml POST /v1/templates
openapi: 3.1.0
info:
  title: OneXtel Truecaller Business Messaging API
  version: 1.0.0
  description: >
    Send verified business messages to Truecaller users: single messages,
    templates with

    personalisation, images, files and buttons, and campaigns to contact lists.


    Every request carries a workspace API key in the `x-api-key` header. Create
    one in the

    Truecaller campaigns portal under **Developers → API keys**.


    Errors are JSON with a single `error` string (and `details` for validation
    errors):


    ```json

    { "error": "invalid phone number" }

    ```
servers:
  - url: https://truecaller.udchowdhury.me
    description: Production
security:
  - apiKey: []
tags:
  - name: Messages
    description: Send one message and read its status.
  - name: Templates
    description: Reusable messages with variables, media and buttons.
  - name: Media
    description: Upload files to attach to templates.
  - name: Contact lists
    description: Audiences for campaigns.
  - name: Campaigns
    description: Send a template to a whole contact list, now or later.
  - name: Senders
    description: The verified business profiles your workspace sends from.
paths:
  /v1/templates:
    post:
      tags:
        - Templates
      summary: Create a template
      description: >
        Creates a template as a draft. Use `{{variable}}` placeholders in the
        body, button

        labels and button URLs; they are filled from contact list columns of the
        same name, or

        from `variables` on a single send. Submit it before sending.
      operationId: createTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TemplateInput'
            example:
              name: Order shipped
              category: transactional
              body: Hi {{name}}, your order *{{order_id}}* has shipped.
              variable_defaults:
                name: there
              media:
                url: https://example.com/box.jpg
                mime_type: image/jpeg
              buttons:
                - type: link
                  text: Track order
                  url: https://example.com/t/{{order_id}}
      responses:
        '201':
          description: Created, as a draft.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Template'
        '400':
          $ref: '#/components/responses/BadRequest'
        '409':
          description: A template with this name exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    TemplateInput:
      type: object
      required:
        - name
        - category
        - body
      properties:
        name:
          type: string
          maxLength: 100
        category:
          type: string
          enum:
            - promotional
            - transactional
            - service
        body:
          type: string
          maxLength: 1000
          description: >-
            Message text with {{variable}} placeholders and Truecaller text
            styling.
        variable_defaults:
          type: object
          additionalProperties:
            type: string
            maxLength: 200
          description: Used when a contact's value is empty.
        media:
          oneOf:
            - $ref: '#/components/schemas/Media'
            - type: 'null'
        buttons:
          type: array
          maxItems: 3
          items:
            $ref: '#/components/schemas/Button'
    Template:
      allOf:
        - $ref: '#/components/schemas/TemplateInput'
        - type: object
          properties:
            id:
              type: string
              format: uuid
            variables:
              type: array
              items:
                type: string
              example:
                - name
                - order_id
            status:
              type: string
              enum:
                - draft
                - submitted
                - approved
                - rejected
            reject_reason:
              type:
                - string
                - 'null'
            created_at:
              type: string
              format: date-time
            updated_at:
              type: string
              format: date-time
    Error:
      type: object
      properties:
        error:
          type: string
        details:
          type: array
          items:
            type: object
    Media:
      type: object
      required:
        - url
        - mime_type
      description: >-
        One attachment. Upload with [Upload
        media](/api-reference/truecaller/upload-media), or give any public https
        URL.
      properties:
        url:
          type: string
          description: Public https URL Truecaller downloads the file from at send time.
        mime_type:
          type: string
          enum:
            - image/jpeg
            - image/png
            - image/gif
            - video/mp4
            - video/quicktime
            - application/pdf
            - text/plain
        file_name:
          type: string
          maxLength: 100
          description: Shown to the recipient for PDFs and text files.
    Button:
      description: Up to 3 per message. Labels and URLs can use `{{variables}}`.
      oneOf:
        - type: object
          title: Link button
          required:
            - type
            - text
            - url
          properties:
            type:
              type: string
              const: link
            text:
              type: string
              maxLength: 40
              example: Track order
            url:
              type: string
              maxLength: 1000
              description: An https URL or an app deep link. Plain http is rejected.
              example: https://example.com/t/{{order_id}}
        - type: object
          title: Quick reply
          required:
            - type
            - text
          properties:
            type:
              type: string
              const: reply
            text:
              type: string
              maxLength: 100
              description: Sent back as the person's reply when tapped.
              example: Call me back
  responses:
    BadRequest:
      description: >-
        The request is invalid. `details` lists each problem for validation
        errors.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: invalid body
            details:
              - path:
                  - to
                message: Required
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Workspace API key from **Developers → API keys**. It starts with
        `tc_live_`.

````

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