Create Filter Segment
curl --request POST \
--url https://api-{dc}.moengage.com/v3/custom-segments \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--header 'MOE-APPKEY: <moe-appkey>' \
--data '
{
"name": "segment_example_name",
"included_filters": {
"filter_operator": "and",
"filters": [
{
"filter_type": "user_attributes",
"name": "Name",
"data_type": "string",
"operator": "in",
"value": [
"Chandan",
"Kumar"
],
"negate": false,
"case_sensitive": false
}
]
}
}
'import requests
url = "https://api-{dc}.moengage.com/v3/custom-segments"
payload = {
"name": "segment_example_name",
"included_filters": {
"filter_operator": "and",
"filters": [
{
"filter_type": "user_attributes",
"name": "Name",
"data_type": "string",
"operator": "in",
"value": ["Chandan", "Kumar"],
"negate": False,
"case_sensitive": False
}
]
}
}
headers = {
"MOE-APPKEY": "<moe-appkey>",
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'MOE-APPKEY': '<moe-appkey>',
Authorization: 'Basic <encoded-value>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'segment_example_name',
included_filters: {
filter_operator: 'and',
filters: [
{
filter_type: 'user_attributes',
name: 'Name',
data_type: 'string',
operator: 'in',
value: ['Chandan', 'Kumar'],
negate: false,
case_sensitive: false
}
]
}
})
};
fetch('https://api-{dc}.moengage.com/v3/custom-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-{dc}.moengage.com/v3/custom-segments",
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' => 'segment_example_name',
'included_filters' => [
'filter_operator' => 'and',
'filters' => [
[
'filter_type' => 'user_attributes',
'name' => 'Name',
'data_type' => 'string',
'operator' => 'in',
'value' => [
'Chandan',
'Kumar'
],
'negate' => false,
'case_sensitive' => false
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json",
"MOE-APPKEY: <moe-appkey>"
],
]);
$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-{dc}.moengage.com/v3/custom-segments"
payload := strings.NewReader("{\n \"name\": \"segment_example_name\",\n \"included_filters\": {\n \"filter_operator\": \"and\",\n \"filters\": [\n {\n \"filter_type\": \"user_attributes\",\n \"name\": \"Name\",\n \"data_type\": \"string\",\n \"operator\": \"in\",\n \"value\": [\n \"Chandan\",\n \"Kumar\"\n ],\n \"negate\": false,\n \"case_sensitive\": false\n }\n ]\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("MOE-APPKEY", "<moe-appkey>")
req.Header.Add("Authorization", "Basic <encoded-value>")
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://api-{dc}.moengage.com/v3/custom-segments")
.header("MOE-APPKEY", "<moe-appkey>")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"segment_example_name\",\n \"included_filters\": {\n \"filter_operator\": \"and\",\n \"filters\": [\n {\n \"filter_type\": \"user_attributes\",\n \"name\": \"Name\",\n \"data_type\": \"string\",\n \"operator\": \"in\",\n \"value\": [\n \"Chandan\",\n \"Kumar\"\n ],\n \"negate\": false,\n \"case_sensitive\": false\n }\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-{dc}.moengage.com/v3/custom-segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["MOE-APPKEY"] = '<moe-appkey>'
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"segment_example_name\",\n \"included_filters\": {\n \"filter_operator\": \"and\",\n \"filters\": [\n {\n \"filter_type\": \"user_attributes\",\n \"name\": \"Name\",\n \"data_type\": \"string\",\n \"operator\": \"in\",\n \"value\": [\n \"Chandan\",\n \"Kumar\"\n ],\n \"negate\": false,\n \"case_sensitive\": false\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"name": "custom-segment name",
"id": "custom-segment id",
"created_time": "2022-12-20T06:21:44.112000",
"updated_time": "2022-12-20T06:21:44.160000",
"type": "ELASTIC_SEARCH",
"source": "API",
"description": "Subscription Status 19Dec_7 is active (case insensitive) AND Has executed Email Sent atleast 1 time in-between Jan 05, 2021 and Jan 08, 2021",
"included_filters": {
"filter_operator": "and",
"filters": [
{
"filter_type": "user_attributes",
"name": "Subscription Status 19Dec_7",
"data_type": "string",
"operator": "in",
"value": [
"active"
],
"negate": false,
"case_sensitive": false
},
{
"filter_type": "actions",
"attributes": {
"filter_operator": "and",
"filters": []
},
"executed": true,
"primary_time_range": {
"type": "between",
"value": "2023-02-15T00:00:00.000Z",
"value1": "2023-02-24T23:59:59.999Z",
"value_type": "absolute",
"period_unit": "days"
},
"action_name": "MOE_EMAIL_SENT",
"execution": {
"count": 1,
"type": "atleast"
}
}
]
}
},
"response_id": "cNjnTEJw",
"type": "custom_segment"
}
Custom Segments - Filters
Create Filter Segment
Creates a new custom segment based on a set of filter conditions.
POST
/
v3
/
custom-segments
Create Filter Segment
curl --request POST \
--url https://api-{dc}.moengage.com/v3/custom-segments \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--header 'MOE-APPKEY: <moe-appkey>' \
--data '
{
"name": "segment_example_name",
"included_filters": {
"filter_operator": "and",
"filters": [
{
"filter_type": "user_attributes",
"name": "Name",
"data_type": "string",
"operator": "in",
"value": [
"Chandan",
"Kumar"
],
"negate": false,
"case_sensitive": false
}
]
}
}
'import requests
url = "https://api-{dc}.moengage.com/v3/custom-segments"
payload = {
"name": "segment_example_name",
"included_filters": {
"filter_operator": "and",
"filters": [
{
"filter_type": "user_attributes",
"name": "Name",
"data_type": "string",
"operator": "in",
"value": ["Chandan", "Kumar"],
"negate": False,
"case_sensitive": False
}
]
}
}
headers = {
"MOE-APPKEY": "<moe-appkey>",
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'MOE-APPKEY': '<moe-appkey>',
Authorization: 'Basic <encoded-value>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'segment_example_name',
included_filters: {
filter_operator: 'and',
filters: [
{
filter_type: 'user_attributes',
name: 'Name',
data_type: 'string',
operator: 'in',
value: ['Chandan', 'Kumar'],
negate: false,
case_sensitive: false
}
]
}
})
};
fetch('https://api-{dc}.moengage.com/v3/custom-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-{dc}.moengage.com/v3/custom-segments",
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' => 'segment_example_name',
'included_filters' => [
'filter_operator' => 'and',
'filters' => [
[
'filter_type' => 'user_attributes',
'name' => 'Name',
'data_type' => 'string',
'operator' => 'in',
'value' => [
'Chandan',
'Kumar'
],
'negate' => false,
'case_sensitive' => false
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json",
"MOE-APPKEY: <moe-appkey>"
],
]);
$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-{dc}.moengage.com/v3/custom-segments"
payload := strings.NewReader("{\n \"name\": \"segment_example_name\",\n \"included_filters\": {\n \"filter_operator\": \"and\",\n \"filters\": [\n {\n \"filter_type\": \"user_attributes\",\n \"name\": \"Name\",\n \"data_type\": \"string\",\n \"operator\": \"in\",\n \"value\": [\n \"Chandan\",\n \"Kumar\"\n ],\n \"negate\": false,\n \"case_sensitive\": false\n }\n ]\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("MOE-APPKEY", "<moe-appkey>")
req.Header.Add("Authorization", "Basic <encoded-value>")
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://api-{dc}.moengage.com/v3/custom-segments")
.header("MOE-APPKEY", "<moe-appkey>")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"segment_example_name\",\n \"included_filters\": {\n \"filter_operator\": \"and\",\n \"filters\": [\n {\n \"filter_type\": \"user_attributes\",\n \"name\": \"Name\",\n \"data_type\": \"string\",\n \"operator\": \"in\",\n \"value\": [\n \"Chandan\",\n \"Kumar\"\n ],\n \"negate\": false,\n \"case_sensitive\": false\n }\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-{dc}.moengage.com/v3/custom-segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["MOE-APPKEY"] = '<moe-appkey>'
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"segment_example_name\",\n \"included_filters\": {\n \"filter_operator\": \"and\",\n \"filters\": [\n {\n \"filter_type\": \"user_attributes\",\n \"name\": \"Name\",\n \"data_type\": \"string\",\n \"operator\": \"in\",\n \"value\": [\n \"Chandan\",\n \"Kumar\"\n ],\n \"negate\": false,\n \"case_sensitive\": false\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"name": "custom-segment name",
"id": "custom-segment id",
"created_time": "2022-12-20T06:21:44.112000",
"updated_time": "2022-12-20T06:21:44.160000",
"type": "ELASTIC_SEARCH",
"source": "API",
"description": "Subscription Status 19Dec_7 is active (case insensitive) AND Has executed Email Sent atleast 1 time in-between Jan 05, 2021 and Jan 08, 2021",
"included_filters": {
"filter_operator": "and",
"filters": [
{
"filter_type": "user_attributes",
"name": "Subscription Status 19Dec_7",
"data_type": "string",
"operator": "in",
"value": [
"active"
],
"negate": false,
"case_sensitive": false
},
{
"filter_type": "actions",
"attributes": {
"filter_operator": "and",
"filters": []
},
"executed": true,
"primary_time_range": {
"type": "between",
"value": "2023-02-15T00:00:00.000Z",
"value1": "2023-02-24T23:59:59.999Z",
"value_type": "absolute",
"period_unit": "days"
},
"action_name": "MOE_EMAIL_SENT",
"execution": {
"count": 1,
"type": "atleast"
}
}
]
}
},
"response_id": "cNjnTEJw",
"type": "custom_segment"
}
Generate Request from Dashboard
To simplify the request generation, MoEngage has added an option in the dashboard where you can specify filters as per your requirement and generate the payload.- Login to the MoEngage dashboard.
- Click on Test & Debug at the bottom left in the side panel.
- Click on Segment Payload.
- Specify the name for your segment payload and provide the required filters.
- Click on the Generate payload button.
Authorizations
Basic Authentication using your Workspace ID (as username) and Data API Key (as password) from the MoEngage Dashboard.
Headers
The Workspace ID (APP ID) of your MoEngage account.
Body
application/json
The filter definition for the new segment.
Response
Custom segment created successfully. Returns the newly created segment details including its unique ID, filter definition, and metadata.
Was this page helpful?
⌘I