Set Opening Templates by Segment
Choose a task’s opening WhatsApp template by lead segment, for example one template per campaign. The list you send replaces the whole configuration.
PUT
/
template-pools
/
opening-segments
Set Opening Templates by Segment
curl --request PUT \
--url https://api.getnexor.ai/api/public/template-pools/opening-segments \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"workflow_id": "7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10",
"segments": [
{
"name": "Instagram",
"condition_rules": {
"field": "metadata.campaign",
"op": "==",
"value": "instagram"
},
"templates": [
{
"name": "spring_promo_ig_v1",
"weight": 3
},
{
"name": "spring_promo_ig_v2"
}
]
},
{
"name": "TikTok",
"condition_rules": {
"field": "metadata.campaign",
"op": "in",
"value": [
"tiktok",
"tiktok_ads"
]
},
"templates": [
{
"name": "spring_promo_tiktok_v1"
}
]
},
{
"name": "Everyone else",
"templates": [
{
"name": "spring_promo_general_v1"
}
]
}
]
}
'import requests
url = "https://api.getnexor.ai/api/public/template-pools/opening-segments"
payload = {
"workflow_id": "7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10",
"segments": [
{
"name": "Instagram",
"condition_rules": {
"field": "metadata.campaign",
"op": "==",
"value": "instagram"
},
"templates": [{
"name": "spring_promo_ig_v1",
"weight": 3
}, { "name": "spring_promo_ig_v2" }]
},
{
"name": "TikTok",
"condition_rules": {
"field": "metadata.campaign",
"op": "in",
"value": ["tiktok", "tiktok_ads"]
},
"templates": [{ "name": "spring_promo_tiktok_v1" }]
},
{
"name": "Everyone else",
"templates": [{ "name": "spring_promo_general_v1" }]
}
]
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
workflow_id: '7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10',
segments: [
{
name: 'Instagram',
condition_rules: {field: 'metadata.campaign', op: '==', value: 'instagram'},
templates: [{name: 'spring_promo_ig_v1', weight: 3}, {name: 'spring_promo_ig_v2'}]
},
{
name: 'TikTok',
condition_rules: {field: 'metadata.campaign', op: 'in', value: ['tiktok', 'tiktok_ads']},
templates: [{name: 'spring_promo_tiktok_v1'}]
},
{name: 'Everyone else', templates: [{name: 'spring_promo_general_v1'}]}
]
})
};
fetch('https://api.getnexor.ai/api/public/template-pools/opening-segments', 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://api.getnexor.ai/api/public/template-pools/opening-segments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'workflow_id' => '7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10',
'segments' => [
[
'name' => 'Instagram',
'condition_rules' => [
'field' => 'metadata.campaign',
'op' => '==',
'value' => 'instagram'
],
'templates' => [
[
'name' => 'spring_promo_ig_v1',
'weight' => 3
],
[
'name' => 'spring_promo_ig_v2'
]
]
],
[
'name' => 'TikTok',
'condition_rules' => [
'field' => 'metadata.campaign',
'op' => 'in',
'value' => [
'tiktok',
'tiktok_ads'
]
],
'templates' => [
[
'name' => 'spring_promo_tiktok_v1'
]
]
],
[
'name' => 'Everyone else',
'templates' => [
[
'name' => 'spring_promo_general_v1'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$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://api.getnexor.ai/api/public/template-pools/opening-segments"
payload := strings.NewReader("{\n \"workflow_id\": \"7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10\",\n \"segments\": [\n {\n \"name\": \"Instagram\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"==\",\n \"value\": \"instagram\"\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_ig_v1\",\n \"weight\": 3\n },\n {\n \"name\": \"spring_promo_ig_v2\"\n }\n ]\n },\n {\n \"name\": \"TikTok\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"in\",\n \"value\": [\n \"tiktok\",\n \"tiktok_ads\"\n ]\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_tiktok_v1\"\n }\n ]\n },\n {\n \"name\": \"Everyone else\",\n \"templates\": [\n {\n \"name\": \"spring_promo_general_v1\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("X-API-Key", "<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.put("https://api.getnexor.ai/api/public/template-pools/opening-segments")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"workflow_id\": \"7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10\",\n \"segments\": [\n {\n \"name\": \"Instagram\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"==\",\n \"value\": \"instagram\"\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_ig_v1\",\n \"weight\": 3\n },\n {\n \"name\": \"spring_promo_ig_v2\"\n }\n ]\n },\n {\n \"name\": \"TikTok\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"in\",\n \"value\": [\n \"tiktok\",\n \"tiktok_ads\"\n ]\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_tiktok_v1\"\n }\n ]\n },\n {\n \"name\": \"Everyone else\",\n \"templates\": [\n {\n \"name\": \"spring_promo_general_v1\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.getnexor.ai/api/public/template-pools/opening-segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"workflow_id\": \"7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10\",\n \"segments\": [\n {\n \"name\": \"Instagram\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"==\",\n \"value\": \"instagram\"\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_ig_v1\",\n \"weight\": 3\n },\n {\n \"name\": \"spring_promo_ig_v2\"\n }\n ]\n },\n {\n \"name\": \"TikTok\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"in\",\n \"value\": [\n \"tiktok\",\n \"tiktok_ads\"\n ]\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_tiktok_v1\"\n }\n ]\n },\n {\n \"name\": \"Everyone else\",\n \"templates\": [\n {\n \"name\": \"spring_promo_general_v1\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"opening_segments": [
{
"name": "Instagram",
"condition_rules": {
"field": "metadata.campaign",
"op": "==",
"value": "instagram"
},
"templates": [
{
"name": "spring_promo_ig_v1",
"weight": 3
},
{
"name": "spring_promo_ig_v2",
"weight": 1
}
]
},
{
"name": "TikTok",
"condition_rules": {
"field": "metadata.campaign",
"op": "in",
"value": [
"tiktok",
"tiktok_ads"
]
},
"templates": [
{
"name": "spring_promo_tiktok_v1",
"weight": 1
}
]
},
{
"name": "Everyone else",
"condition_rules": null,
"templates": [
{
"name": "spring_promo_general_v1",
"weight": 1
}
]
}
]
}Use this when leads of the same task should get a different first WhatsApp message depending on where they came from, for example one template per campaign for leads you upload in bulk. Read the current segments with Get a WhatsApp Template Pool (
A segment without
opening_segments). MCP keys need whatsapp:write; the MCP tool is set_opening_segments.
Set the segments
{
"workflow_id": "7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10",
"segments": [
{
"name": "Instagram",
"condition_rules": { "field": "metadata.campaign", "op": "==", "value": "instagram" },
"templates": [
{ "name": "spring_promo_ig_v1", "weight": 3 },
{ "name": "spring_promo_ig_v2" }
]
},
{
"name": "TikTok",
"condition_rules": { "field": "metadata.campaign", "op": "in", "value": ["tiktok", "tiktok_ads"] },
"templates": [{ "name": "spring_promo_tiktok_v1" }]
},
{
"name": "Everyone else",
"templates": [{ "name": "spring_promo_general_v1" }]
}
]
}
- The list replaces the whole configuration. Send every segment you want to keep.
"segments": []removes it. - Up to 20 segments. Each
nameis required and appears once. - Segments are checked in order. The first one whose
condition_rulesmatch the lead wins. - Inside a segment, one template is drawn by
weight: an integer from 1 to 100,1when you leave it out. In the example,spring_promo_ig_v1goes out about three times as often asspring_promo_ig_v2. - Each segment has 1 to 10 templates, with no repeated names inside a segment.
- Every template must be APPROVED on the account’s WhatsApp and written in the agent’s language.
Who gets which template
| Lead | Opening template |
|---|---|
Matches a segment’s condition_rules | One template of the first matching segment, drawn by weight |
Matches no segment, and the last segment has no condition_rules | One template of that last segment (the catch-all) |
| Matches no segment, and there is no catch-all | The task’s normal opening template, set with Configure Opening Templates |
condition_rules is the catch-all and must be the last one. Without a catch-all, leads that don’t carry the segment field keep getting the normal opening template.
Condition rules
A rule is{ "field", "op", "value" }, or a group { "operator": "and" | "or", "rules": [...] } with up to 10 single rules. Groups do not nest.
| Part | Values |
|---|---|
field | A lead path: metadata.<key> (for example a column of the file you uploaded), raw_payload.<key>, or source (csv_import, api, …) |
op | ==, !=, >, <, >=, <=, in (value is an array), exists (no value), days_until_lt, days_until_lte, days_until_gt, days_until_gte (days left until a date in field) |
value | What to compare against. Required for every op except exists |
{
"operator": "and",
"rules": [
{ "field": "source", "op": "==", "value": "csv_import" },
{ "field": "metadata.campaign", "op": "==", "value": "instagram" }
]
}
Errors
| Status | When |
|---|---|
400 Invalid input | Wrong shape or limits, duplicate names, a catch-all that is not last, or a template that is unknown or not APPROVED. message names the segment or template |
400 INVALID_CONDITION_RULES | A malformed rule. reason gives the cause, for example condition_rules_in_needs_array |
400 TEMPLATE_LANGUAGE_MISMATCH | A template is not in the agent’s language. Pick one in that language |
| 404 | The task does not exist in this account |
Authorizations
Body
application/json
Last modified on November 10, 2026
⌘I
Set Opening Templates by Segment
curl --request PUT \
--url https://api.getnexor.ai/api/public/template-pools/opening-segments \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"workflow_id": "7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10",
"segments": [
{
"name": "Instagram",
"condition_rules": {
"field": "metadata.campaign",
"op": "==",
"value": "instagram"
},
"templates": [
{
"name": "spring_promo_ig_v1",
"weight": 3
},
{
"name": "spring_promo_ig_v2"
}
]
},
{
"name": "TikTok",
"condition_rules": {
"field": "metadata.campaign",
"op": "in",
"value": [
"tiktok",
"tiktok_ads"
]
},
"templates": [
{
"name": "spring_promo_tiktok_v1"
}
]
},
{
"name": "Everyone else",
"templates": [
{
"name": "spring_promo_general_v1"
}
]
}
]
}
'import requests
url = "https://api.getnexor.ai/api/public/template-pools/opening-segments"
payload = {
"workflow_id": "7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10",
"segments": [
{
"name": "Instagram",
"condition_rules": {
"field": "metadata.campaign",
"op": "==",
"value": "instagram"
},
"templates": [{
"name": "spring_promo_ig_v1",
"weight": 3
}, { "name": "spring_promo_ig_v2" }]
},
{
"name": "TikTok",
"condition_rules": {
"field": "metadata.campaign",
"op": "in",
"value": ["tiktok", "tiktok_ads"]
},
"templates": [{ "name": "spring_promo_tiktok_v1" }]
},
{
"name": "Everyone else",
"templates": [{ "name": "spring_promo_general_v1" }]
}
]
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
workflow_id: '7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10',
segments: [
{
name: 'Instagram',
condition_rules: {field: 'metadata.campaign', op: '==', value: 'instagram'},
templates: [{name: 'spring_promo_ig_v1', weight: 3}, {name: 'spring_promo_ig_v2'}]
},
{
name: 'TikTok',
condition_rules: {field: 'metadata.campaign', op: 'in', value: ['tiktok', 'tiktok_ads']},
templates: [{name: 'spring_promo_tiktok_v1'}]
},
{name: 'Everyone else', templates: [{name: 'spring_promo_general_v1'}]}
]
})
};
fetch('https://api.getnexor.ai/api/public/template-pools/opening-segments', 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://api.getnexor.ai/api/public/template-pools/opening-segments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'workflow_id' => '7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10',
'segments' => [
[
'name' => 'Instagram',
'condition_rules' => [
'field' => 'metadata.campaign',
'op' => '==',
'value' => 'instagram'
],
'templates' => [
[
'name' => 'spring_promo_ig_v1',
'weight' => 3
],
[
'name' => 'spring_promo_ig_v2'
]
]
],
[
'name' => 'TikTok',
'condition_rules' => [
'field' => 'metadata.campaign',
'op' => 'in',
'value' => [
'tiktok',
'tiktok_ads'
]
],
'templates' => [
[
'name' => 'spring_promo_tiktok_v1'
]
]
],
[
'name' => 'Everyone else',
'templates' => [
[
'name' => 'spring_promo_general_v1'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$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://api.getnexor.ai/api/public/template-pools/opening-segments"
payload := strings.NewReader("{\n \"workflow_id\": \"7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10\",\n \"segments\": [\n {\n \"name\": \"Instagram\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"==\",\n \"value\": \"instagram\"\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_ig_v1\",\n \"weight\": 3\n },\n {\n \"name\": \"spring_promo_ig_v2\"\n }\n ]\n },\n {\n \"name\": \"TikTok\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"in\",\n \"value\": [\n \"tiktok\",\n \"tiktok_ads\"\n ]\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_tiktok_v1\"\n }\n ]\n },\n {\n \"name\": \"Everyone else\",\n \"templates\": [\n {\n \"name\": \"spring_promo_general_v1\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("X-API-Key", "<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.put("https://api.getnexor.ai/api/public/template-pools/opening-segments")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"workflow_id\": \"7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10\",\n \"segments\": [\n {\n \"name\": \"Instagram\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"==\",\n \"value\": \"instagram\"\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_ig_v1\",\n \"weight\": 3\n },\n {\n \"name\": \"spring_promo_ig_v2\"\n }\n ]\n },\n {\n \"name\": \"TikTok\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"in\",\n \"value\": [\n \"tiktok\",\n \"tiktok_ads\"\n ]\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_tiktok_v1\"\n }\n ]\n },\n {\n \"name\": \"Everyone else\",\n \"templates\": [\n {\n \"name\": \"spring_promo_general_v1\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.getnexor.ai/api/public/template-pools/opening-segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"workflow_id\": \"7d3c1a52-5b8e-4f0e-9c1a-2b6f4e8d9a10\",\n \"segments\": [\n {\n \"name\": \"Instagram\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"==\",\n \"value\": \"instagram\"\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_ig_v1\",\n \"weight\": 3\n },\n {\n \"name\": \"spring_promo_ig_v2\"\n }\n ]\n },\n {\n \"name\": \"TikTok\",\n \"condition_rules\": {\n \"field\": \"metadata.campaign\",\n \"op\": \"in\",\n \"value\": [\n \"tiktok\",\n \"tiktok_ads\"\n ]\n },\n \"templates\": [\n {\n \"name\": \"spring_promo_tiktok_v1\"\n }\n ]\n },\n {\n \"name\": \"Everyone else\",\n \"templates\": [\n {\n \"name\": \"spring_promo_general_v1\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"opening_segments": [
{
"name": "Instagram",
"condition_rules": {
"field": "metadata.campaign",
"op": "==",
"value": "instagram"
},
"templates": [
{
"name": "spring_promo_ig_v1",
"weight": 3
},
{
"name": "spring_promo_ig_v2",
"weight": 1
}
]
},
{
"name": "TikTok",
"condition_rules": {
"field": "metadata.campaign",
"op": "in",
"value": [
"tiktok",
"tiktok_ads"
]
},
"templates": [
{
"name": "spring_promo_tiktok_v1",
"weight": 1
}
]
},
{
"name": "Everyone else",
"condition_rules": null,
"templates": [
{
"name": "spring_promo_general_v1",
"weight": 1
}
]
}
]
}