Skip to main content
POST
/
notifications
/
messages
Send a notification using a template
curl --request POST \
  --url https://{appId}.api-{region}.cometchat.io/v3/campaigns/notifications/messages \
  --header 'Content-Type: application/json' \
  --header 'apikey: <api-key>' \
  --header 'appid: <appid>' \
  --data '
{
  "templateId": "order_update",
  "receivers": [
    "<string>"
  ],
  "variables": {
    "user_42": {
      "user_name": "John",
      "order_id": "12345"
    },
    "user_43": {
      "user_name": "Sarah",
      "order_id": "12346"
    }
  },
  "tag": "<string>"
}
'
import requests

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

payload = {
"templateId": "order_update",
"receivers": ["<string>"],
"variables": {
"user_42": {
"user_name": "John",
"order_id": "12345"
},
"user_43": {
"user_name": "Sarah",
"order_id": "12346"
}
},
"tag": "<string>"
}
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({
templateId: 'order_update',
receivers: ['<string>'],
variables: {
user_42: {user_name: 'John', order_id: '12345'},
user_43: {user_name: 'Sarah', order_id: '12346'}
},
tag: '<string>'
})
};

fetch('https://{appId}.api-{region}.cometchat.io/v3/campaigns/notifications/messages', 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/notifications/messages",
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([
'templateId' => 'order_update',
'receivers' => [
'<string>'
],
'variables' => [
'user_42' => [
'user_name' => 'John',
'order_id' => '12345'
],
'user_43' => [
'user_name' => 'Sarah',
'order_id' => '12346'
]
],
'tag' => '<string>'
]),
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/notifications/messages"

payload := strings.NewReader("{\n \"templateId\": \"order_update\",\n \"receivers\": [\n \"<string>\"\n ],\n \"variables\": {\n \"user_42\": {\n \"user_name\": \"John\",\n \"order_id\": \"12345\"\n },\n \"user_43\": {\n \"user_name\": \"Sarah\",\n \"order_id\": \"12346\"\n }\n },\n \"tag\": \"<string>\"\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/notifications/messages")
.header("appid", "<appid>")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"templateId\": \"order_update\",\n \"receivers\": [\n \"<string>\"\n ],\n \"variables\": {\n \"user_42\": {\n \"user_name\": \"John\",\n \"order_id\": \"12345\"\n },\n \"user_43\": {\n \"user_name\": \"Sarah\",\n \"order_id\": \"12346\"\n }\n },\n \"tag\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

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

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 \"templateId\": \"order_update\",\n \"receivers\": [\n \"<string>\"\n ],\n \"variables\": {\n \"user_42\": {\n \"user_name\": \"John\",\n \"order_id\": \"12345\"\n },\n \"user_43\": {\n \"user_name\": \"Sarah\",\n \"order_id\": \"12346\"\n }\n },\n \"tag\": \"<string>\"\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
templateId
string
required

Template CUID or templateId slug. Template must be in approved status.

Example:

"order_update"

receivers
string[]
required

Array of target user IDs. 1–10 = realtime (synchronous, returns notificationId immediately). 11–10,000 = batch (asynchronous, returns batchId; processing happens via queue).

Required array length: 1 - 10000 elements
variables
object

Per-user variables. Keyed by userId; values are { variableName: value } objects. Variables are applied to the template content at delivery time.

Example:
{
"user_42": { "user_name": "John", "order_id": "12345" },
"user_43": { "user_name": "Sarah", "order_id": "12346" }
}
tag
string

Optional analytics tag attached to the send (passes through to delivery records).

Response

Realtime: { notificationId, channels[], mode: "realtime" }. Batch: { batchId, total, channels[], mode: "batch" }.