Получение шаблонов#
Получение шаблона по id#
GET https://direct.i-dgtl.ru/api/v1/templates/{template_id}
Метод позволяет получить объект шаблона с указанным id.
Path Parameters#
Name |
Type |
Description |
|---|---|---|
template_id* |
integer |
Идентификатор запрашиваемого шаблона |
Headers#
Name |
Type |
Description |
|---|---|---|
Authorization* |
string |
|
{
"id": 1234,
"channelType": "SMS",
"templateType": "SERVICE",
"pattern": "привет, %w",
"dateFrom": "2020-07-07T21:00:00Z",
"dateTo": "2020-10-10T00:00:00Z",
"senderNameId": 1234,
"senderName": "testsend",
"brand": "BEELINE",
"managerComment": "комментарий менеджера",
"status": "CLOSED",
"createdAt": "2020-06-01T21:00:00Z",
"rejectedAt": "2020-06-07T21:00:00Z"
}
Использование невалидного токена / отсутствие заголовка авторизации.
{
"error": {
"code": 4012,
"msg": "Bad credentials"
}
}
{
"error": {
"code": 4010,
"msg": "Not Authenticated"
}
}
Использование неподходящего токена.
{
"error": {
"code": 4030,
"msg": "Access Denied"
}
}
Несуществующий template_id.
{
"error": {
"code": 4220,
"msg": "Client 5 has not template 1"
}
}
Описание объекта шаблона #
Параметр |
Тип |
Описание |
|---|---|---|
id |
integer |
Идентификатор шаблона |
channelType |
string |
|
templateType |
string |
|
pattern |
string |
Текст шаблона |
dateFrom |
string |
Дата начала действия |
dateTo |
string |
Дата окончания действия |
senderNameId |
integer |
Идентификатор имени отправителя, на которое зарегистрирован шаблон |
senderName |
string |
Имя отправителя |
brand |
string |
Оператор (только для SMS-шаблонов) |
countryCode |
string |
Код страны (только для VIBER-шаблонов) |
managerComment |
string |
Комментарий менеджера |
status |
string |
|
createdAt |
string |
Дата создания шаблона |
rejectedAt |
string |
Дата отклонения шаблона |
content |
object |
Контент шаблона (только для WHATSAPP-шаблонов, описан ниже) |
Контент WHATSAPP-шаблона #
{
"header": {
"type": "text",
"text": "Текст заголовка {{1}}"
},
"text": "Текст сообщения {{2}}",
"footer": "Текст подписи",
"buttons": [
{
"text": "Текст кнопки 1"
},
{
"text": "Текст кнопки 2"
},
{
"text": "Текст кнопки 3"
}
}
}
{
"header": {
"type": "image"
},
"text": "Текст сообщения {{1}}",
"footer": "Подпись сообщения",
"buttons": [
{
"text": "Кнопка-ссылка",
"url": "https://i-dgtl.ru"
},
{
"text": "Кнопка-вызов",
"phone": "78000000000"
}
]
}
Параметр |
Тип |
Описание |
|---|---|---|
content.header |
object |
Объект с информацией о заголовке сообщения |
content.header.type |
string |
Тип заголовка; принимает значения:
|
content.header.text |
string |
Текст заголовка; присутствует только при |
content.text |
string |
Текст сообщения |
content.footer |
string |
Подпись сообщения |
content.buttons |
array |
Массив объектов с кнопками |
content.buttons.text |
string |
Текст кнопки |
content.buttons.url |
string |
Ссылка, на которую произойдет переход при нажатии на кнопку |
content.buttons.phone |
string |
Телефонный номер, на который произойдет вызов при нажатии на кнопку |
Формирование WHATSAPP-сообщения#
Для того, чтобы сформировать из WHATSAPP-шаблона контент WHATSAPP-сообщения, необходимо:
Добавить параметр
content.contentTypeсо значением"text"Заполнить подстановки: параметры
content.header.textиcontent.textмогут содержать переменные вида {{1}}, {{2}}, которые необходимо заменить на строкиУдалить параметр
content.header.typeиз заголовкаДобавить интерактивное содержимое в заголовок:
если
content.header.type = document, то нужно добавитьcontent.header.documentUrl— ссылка на документcontent.header.documentName— название документа, которое будет отображено абоненту
если
content.header.type = image, то нужно добавитьcontent.header.imageUrl— ссылка на изображение
Преобразовать строку
content.footerв строкуcontent.footer.text, добавив вложенный объектcontent.footerДля кнопок, у которых отсутствует
content.buttons.url/content.buttons.phone, необходимо добавить строкуcontent.buttons.payload
Получение массива шаблонов#
GET https://direct.i-dgtl.ru/api/v1/templates
Метод позволяет получить массив объектов шаблонов, подходящих под условия фильтрации.
Query Parameters#
Name |
Type |
Description |
|---|---|---|
page |
string |
Номер запрашиваемой страницы |
per_page |
string |
Количество записей на странице |
template_id |
string |
Идентификатор шаблона |
sender_name_id |
string |
Фильтрация по идентификатору имени отправителя |
sender_name |
string |
Фильтрация по имени отправителя (поиск по полному соответствию) |
channel_type |
string |
Фильтрация по каналу |
brand |
string |
Фильтрация по оператору |
country_code |
string |
Фильтрация по коду страны |
status |
string |
Фильтрация по статусу |
template_type |
string |
Фильтрация по типу |
pattern |
string |
Фильтрация по тексту шаблона (по наличию подстроки в тексте) |
min_date_from |
string |
Фильтрация по нижнему значению даты начала действия |
min_date_to |
string |
Фильтрация по нижнему значению даты окончания действия |
max_date_from |
string |
Фильтрация по верхнему значению даты начала действия |
max_date_to |
string |
Фильтрация по верхнему значению даты окончания действия |
Headers#
Name |
Type |
Description |
|---|---|---|
Authorization |
string |
|
{
"page": 1,
"perPage": 2000,
"total": 1,
"items": [
{
"id": 1234,
"channelType": "SMS",
"templateType": "SERVICE",
"pattern": "привет, %w",
"dateFrom": "2020-07-07T21:00:00Z",
"dateTo": "2020-10-10T00:00:00Z",
"senderNameId": 1234,
"senderName": "testsend",
"brand": "BEELINE",
"managerComment": "комментарий менеджера",
"status": "CLOSED",
"createdAt": "2020-06-01T21:00:00Z",
"rejectedAt": "2020-06-07T21:00:00Z"
}
]
Возможные варианты перечислений:
Параметр |
Варианты |
|---|---|
channel_type |
|
country_code |
|
brand |
|
status |
|
template_type |
Примеры запроса #
Получение сервисных шаблонов, зарегистрированных на операторов Теле2 и Билайн в статусах «Одобрено» и «Закрыто»
GET https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
curl -X GET 'https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED' \
-H 'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
import requests
import json
url = "https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED"
payload = {}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
};
fetch("https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED")
.method("GET", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json'
];
$request = new Request('GET', 'https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED', $headers);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://direct.i-dgtl.ru/api/v1/templates?template_type=SERVICE&brand=TELE2&brand=BEELINE&status=APPROVED&status=CLOSED"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Получение VIBER-шаблонов, действующих в РФ, в статусе «Одобрено»
GET https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
curl -X GET 'https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED' \
-H 'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
import requests
import json
url = "https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED"
payload = {}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
};
fetch("https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED")
.method("GET", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json'
];
$request = new Request('GET', 'https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED', $headers);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://direct.i-dgtl.ru/api/v1/templates?channel_type=VIBER&country_code=ru&status=APPROVED"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}