Create a new campaign
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--header 'appid: <appid>' \
--data '
{
"name": "<string>",
"templateId": "<string>",
"templateVersion": 2,
"variables": {
"promoCode": "SUMMER25"
},
"config": {}
}
'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns"
payload = {
"name": "<string>",
"templateId": "<string>",
"templateVersion": 2,
"variables": { "promoCode": "SUMMER25" },
"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>',
templateId: '<string>',
templateVersion: 2,
variables: {promoCode: 'SUMMER25'},
config: {}
})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns', 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/campaigns",
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>',
'templateId' => '<string>',
'templateVersion' => 2,
'variables' => [
'promoCode' => 'SUMMER25'
],
'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/campaigns"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"templateId\": \"<string>\",\n \"templateVersion\": 2,\n \"variables\": {\n \"promoCode\": \"SUMMER25\"\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/campaigns")
.header("appid", "<appid>")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"templateId\": \"<string>\",\n \"templateVersion\": 2,\n \"variables\": {\n \"promoCode\": \"SUMMER25\"\n },\n \"config\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns")
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 \"templateId\": \"<string>\",\n \"templateVersion\": 2,\n \"variables\": {\n \"promoCode\": \"SUMMER25\"\n },\n \"config\": {}\n}"
response = http.request(request)
puts response.read_bodyCampaigns
Create a new campaign
Create a new campaign.
POST
/
campaigns
Create a new campaign
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--header 'appid: <appid>' \
--data '
{
"name": "<string>",
"templateId": "<string>",
"templateVersion": 2,
"variables": {
"promoCode": "SUMMER25"
},
"config": {}
}
'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns"
payload = {
"name": "<string>",
"templateId": "<string>",
"templateVersion": 2,
"variables": { "promoCode": "SUMMER25" },
"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>',
templateId: '<string>',
templateVersion: 2,
variables: {promoCode: 'SUMMER25'},
config: {}
})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns', 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/campaigns",
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>',
'templateId' => '<string>',
'templateVersion' => 2,
'variables' => [
'promoCode' => 'SUMMER25'
],
'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/campaigns"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"templateId\": \"<string>\",\n \"templateVersion\": 2,\n \"variables\": {\n \"promoCode\": \"SUMMER25\"\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/campaigns")
.header("appid", "<appid>")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"templateId\": \"<string>\",\n \"templateVersion\": 2,\n \"variables\": {\n \"promoCode\": \"SUMMER25\"\n },\n \"config\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/campaigns/campaigns")
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 \"templateId\": \"<string>\",\n \"templateVersion\": 2,\n \"variables\": {\n \"promoCode\": \"SUMMER25\"\n },\n \"config\": {}\n}"
response = http.request(request)
puts response.read_bodyAuthorizations
Your CometChat REST API Key.
Headers
Tenant application ID
Body
application/json
Campaign name
Template ID (CUID or templateId slug)
Template version number to pin
Required range:
x >= 1Campaign-level default variables — applied to every recipient as a fallback layer below per-user CSV values and above template variableSchema defaults. Example: { "promoCode": "SUMMER25", "supportEmail": "help@acme.io" }.
Example:
{ "promoCode": "SUMMER25" }Additional campaign configuration (free-form)
Response
201
Campaign created
Was this page helpful?
⌘I