Skip to main content
POST
/
templates
Create a new template
curl --request POST \
  --url https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates \
  --header 'Content-Type: application/json' \
  --header 'apikey: <api-key>' \
  --header 'appid: <appid>' \
  --data '
{
  "name": "<string>",
  "channels": [
    {
      "channelType": "<string>",
      "channelId": "<string>",
      "content": {},
      "categoryFilterEnabled": true,
      "templateLabelEnabled": true,
      "messageRetentionHours": 123,
      "sequenceOrder": 123,
      "stopCondition": "<string>"
    }
  ],
  "templateId": "<string>",
  "label": "<string>",
  "alternativeText": "<string>",
  "tags": [
    "<string>"
  ],
  "variableSchema": [
    {}
  ],
  "config": {}
}
'
import requests

url = "https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates"

payload = {
    "name": "<string>",
    "channels": [
        {
            "channelType": "<string>",
            "channelId": "<string>",
            "content": {},
            "categoryFilterEnabled": True,
            "templateLabelEnabled": True,
            "messageRetentionHours": 123,
            "sequenceOrder": 123,
            "stopCondition": "<string>"
        }
    ],
    "templateId": "<string>",
    "label": "<string>",
    "alternativeText": "<string>",
    "tags": ["<string>"],
    "variableSchema": [{}],
    "config": {}
}
headers = {
    "appid": "<appid>",
    "apikey": "<api-key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {appid: '<appid>', apikey: '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    name: '<string>',
    channels: [
      {
        channelType: '<string>',
        channelId: '<string>',
        content: {},
        categoryFilterEnabled: true,
        templateLabelEnabled: true,
        messageRetentionHours: 123,
        sequenceOrder: 123,
        stopCondition: '<string>'
      }
    ],
    templateId: '<string>',
    label: '<string>',
    alternativeText: '<string>',
    tags: ['<string>'],
    variableSchema: [{}],
    config: {}
  })
};

fetch('https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'name' => '<string>',
    'channels' => [
        [
                'channelType' => '<string>',
                'channelId' => '<string>',
                'content' => [
                                
                ],
                'categoryFilterEnabled' => true,
                'templateLabelEnabled' => true,
                'messageRetentionHours' => 123,
                'sequenceOrder' => 123,
                'stopCondition' => '<string>'
        ]
    ],
    'templateId' => '<string>',
    'label' => '<string>',
    'alternativeText' => '<string>',
    'tags' => [
        '<string>'
    ],
    'variableSchema' => [
        [
                
        ]
    ],
    'config' => [
        
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "apikey: <api-key>",
    "appid: <appid>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates"

	payload := strings.NewReader("{\n  \"name\": \"<string>\",\n  \"channels\": [\n    {\n      \"channelType\": \"<string>\",\n      \"channelId\": \"<string>\",\n      \"content\": {},\n      \"categoryFilterEnabled\": true,\n      \"templateLabelEnabled\": true,\n      \"messageRetentionHours\": 123,\n      \"sequenceOrder\": 123,\n      \"stopCondition\": \"<string>\"\n    }\n  ],\n  \"templateId\": \"<string>\",\n  \"label\": \"<string>\",\n  \"alternativeText\": \"<string>\",\n  \"tags\": [\n    \"<string>\"\n  ],\n  \"variableSchema\": [\n    {}\n  ],\n  \"config\": {}\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("appid", "<appid>")
	req.Header.Add("apikey", "<api-key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates")
  .header("appid", "<appid>")
  .header("apikey", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"<string>\",\n  \"channels\": [\n    {\n      \"channelType\": \"<string>\",\n      \"channelId\": \"<string>\",\n      \"content\": {},\n      \"categoryFilterEnabled\": true,\n      \"templateLabelEnabled\": true,\n      \"messageRetentionHours\": 123,\n      \"sequenceOrder\": 123,\n      \"stopCondition\": \"<string>\"\n    }\n  ],\n  \"templateId\": \"<string>\",\n  \"label\": \"<string>\",\n  \"alternativeText\": \"<string>\",\n  \"tags\": [\n    \"<string>\"\n  ],\n  \"variableSchema\": [\n    {}\n  ],\n  \"config\": {}\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://{appId}.api-{region}.cometchat.io/v3/campaigns/templates")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["appid"] = '<appid>'
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"<string>\",\n  \"channels\": [\n    {\n      \"channelType\": \"<string>\",\n      \"channelId\": \"<string>\",\n      \"content\": {},\n      \"categoryFilterEnabled\": true,\n      \"templateLabelEnabled\": true,\n      \"messageRetentionHours\": 123,\n      \"sequenceOrder\": 123,\n      \"stopCondition\": \"<string>\"\n    }\n  ],\n  \"templateId\": \"<string>\",\n  \"label\": \"<string>\",\n  \"alternativeText\": \"<string>\",\n  \"tags\": [\n    \"<string>\"\n  ],\n  \"variableSchema\": [\n    {}\n  ],\n  \"config\": {}\n}"

response = http.request(request)
puts response.read_body

Authorizations

apikey
string
header
required

Your CometChat REST API Key.

Headers

appid
string
required

Tenant application ID

Body

application/json
name
string
required

Template name

channels
object[]
required

Channel configurations

templateId
string

Human-readable slug (auto-generated from name if omitted)

templateCategory
enum<string>

Template category

Available options:
Onboarding,
Transactional,
Marketing,
Product_Showcase,
Alerts,
Polls,
Custom
label
string

Display label shown on notification (e.g. Promo, Alert)

alternativeText
string

Plain-text fallback when push is suppressed or rich content cannot render. Sendbird-parity field.

tags
string[]

First-class tags for filtering/segmentation

status
enum<string>

Template status

Available options:
draft,
approved,
archived
variableSchema
object[]

Variable schema definitions

config
object

Additional configuration

Response

Template created