Sending a template via API

Sending a template is described in the API documentation in the /sendTemplate method.

You can also create a template from the 'Dev Toolkit → 'Test Requests' section in your personal account.

To send a template, you need to know the namespace, name and language of the template. To get this information, call the 'Get list of templates' method (/templates).

Some properties that can cause problems in the /sendTemplate method.

Свойства
Описание

template

It's the name of the template

language

policy: write "deterministiс"

code: language from the /templates method

Object with type "body"

Text message. Can be omitted if there are no variables in the text.

Object with type "button"

You can display only buttons with sub_type ‘url’ or ‘catalog’ in the body. Other types of buttons can be omitted when sending the template

How to send Marketing or Utility templates

In requests, you should only send the objects that you have specified in the created template. For example, if there is no HEADER in the template, do not send it. Objects are also omitted if:

  • Header object of type Text without variable;

  • Body without variable;

  • Quick reply buttons and number buttons are always omitted;

  • URL button without variable.

Header objects of type IMAGE, VIDEO, DOCUMENT always contain the full link to the media document. Note that the link to the media document must contain the format of the document.

Example of sending a Document with URL button

Structure:

  • Header of document type

  • Body contains 2 variables

  • Two URL buttons, the second of which contains a variable.

If a URL button does not have a variable, omit it from the request. For example, in this request, the first URL button with index 0 is omitted, but the second button is output. Note also that the index of the second button is already 1.

{
  "token": "{{token}}",
  "namespace": "{{namespace}}",
  "template": "delivery_tracking",
  "language": {
    "policy": "deterministic",
    "code": "ru"
  },
  "params": [
    {
      "type": "header",
      "parameters": [
        {
          "type": "document", // document object
          "document": {
            "link": "https://test.com/reyshi.pdf" //link to the document. Please note that the link must specify the format of the document
          }
        }
      ]
    },
    {
      "type": "body",
      "parameters": [
        {
          "type": "text",
          "text": "Андрей" // first variable in BODY
        },
        {
          "type": "text",
          "text": "№003478" // second variable in BODY
        }
      ]
    },
    {
      "type": "button", // second URL button
      "sub_type": "url",
      "index":1, // index is numbered starting from zero, the second button has index 1
      "parameters": [
        {
          "type": "text",
          "text": "/reyshi" // link variable
        }
      ]
    }
  ],
  "phone": "{{phone}}"
}

Example of sending a Text Header with all types of buttons

Structure:

  • Header of Text type with one variable

  • The body of the message does not contain a variable. Therefore, it is omitted in the query.

  • 4 buttons. The first button is quick reply, the second is phone button, the third is URL button with variable, the fourth is URL button without variable.

{
  "token": "{{token}}",
  "namespace": "{{namespace}}",
  "template": "utility_all_buttons_2024_05",
  "language": {
    "policy": "deterministic",
    "code": "en"
  },
  "params": [
    {
      "type": "header",
      "parameters": [
        {
          "type": "text",
          "text": "Anna" // header variable
        }
      ]
    },
    {
      "type": "button", // third button, a URL button with a variable
      "sub_type": "url",
      "index": 2, // third button index
      "parameters": [
        {
          "type": "text",
          "text": "inbox" // link variable
        }
      ]
    }
  ],
  "phone": "{{phone}}"
}

The Carousel template is only supported in the Cloud API.

Carousel template:

  • Has its own type - CAROUSEL

  • An object with type CAROUSEL contains an array of cards. It is used only for this template type

  • Each card contains card_index - the order of appearance of cards in the card carousel. 0 - means the first card, 1 - means the second card, etc.

How to send the ‘Catalog’ template

The ‘Catalog’ template is only supported in the Cloud API.

Before you send a catalogue, check if you have it enabled. You can check in your personal account in 360 Dialog, or by calling the /commerce method.

Catalogue template:

  • In the button object, you need to write CATALOG in sub_type . The name of the button is not controllable.

  • In thumbnail_product_retailer_id you can write the article of the product specified in Meta. In this case, the thumbnail of this product will be used as the header image of the post. Otherwise, the product image of the first product in your catalogue will be used.

Example code part when no thumbnail_product_retailer_id is specified.

 {
      "type": "button",
      "sub_type": "CATALOG",
      "index": 0,
      "parameters": [
        {
          "type": "action",
          "action": {
            "thumbnail_product_retailer_id": ""
          }
        }
      ]
    }
Example of sending the ‘Catalog’ template

Because the template did not contain a variable description in the text, object with type "BODY" is omitted when it is sent.

POST https://api.1msg.io/{{channel}}/sendTemplate
Content-Type: application/json
Body: {
  "token": "{{token}}",
  "namespace": "{{namespace}}",
  "template": "catalog_services",
  "language": {
    "policy": "deterministic",
    "code": "en"
  },
  "params": [
    {
      "type": "button",
      "sub_type": "CATALOG",
      "index": 0,
      "parameters": [
        {
          "type": "action",
          "action": {
            "thumbnail_product_retailer_id": "0002" // A thumbnail of this product will be sent. You can send 'thumbnail_product_retailer_id': ''. The product image of the first product in your catalogue will be used.
        }
      ]
    }
  ],
  "phone": "+556123122026"
}
      

How to send the "Authentication" template

Example of sending an authentication template

Example of sending a code copy button

{
  "token": "{{token}}",
  "namespace": "{{namespace}}",
  "template": "auth_2",
  "language": {
    "policy": "deterministic",
    "code": "ru"
  },
  "params": [
        {
      "type": "body",
      "parameters": [
        {
          "type": "text",
          "text": "05425" // code displayed in the message body
        }
      ]
    },
    {
      "type": "BUTTON",
      "sub_type": "URL",
      "index": 0,
      "parameters": [
        {
          "type": "TEXT",
          "text": "05425" // the code that will be copied
        }
      ]
    }
  ],
  "phone": "+556123122026"
}
  

Last updated