curl --request PUT \
--url https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: <content-type>' \
--data '
{
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs_add.csv",
"callback_url": "http://example.com/moengage-callback",
"emails": [
"user1@example.com"
]
}
'import requests
url = "https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users"
payload = {
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs_add.csv",
"callback_url": "http://example.com/moengage-callback",
"emails": ["user1@example.com"]
}
headers = {
"Content-Type": "<content-type>",
"Authorization": "Basic <encoded-value>"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': '<content-type>', Authorization: 'Basic <encoded-value>'},
body: JSON.stringify({
name: 'custom_segment_unique_name',
attribute_name: 'unique_identifier',
attribute_type: 'string',
file_url: 'https://s3.amazonaws.com/Sample_GAIDs_add.csv',
callback_url: 'http://example.com/moengage-callback',
emails: ['user1@example.com']
})
};
fetch('https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users', 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/v2/custom-segments/file-segment/add-users",
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([
'name' => 'custom_segment_unique_name',
'attribute_name' => 'unique_identifier',
'attribute_type' => 'string',
'file_url' => 'https://s3.amazonaws.com/Sample_GAIDs_add.csv',
'callback_url' => 'http://example.com/moengage-callback',
'emails' => [
'user1@example.com'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: <content-type>"
],
]);
$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/v2/custom-segments/file-segment/add-users"
payload := strings.NewReader("{\n \"name\": \"custom_segment_unique_name\",\n \"attribute_name\": \"unique_identifier\",\n \"attribute_type\": \"string\",\n \"file_url\": \"https://s3.amazonaws.com/Sample_GAIDs_add.csv\",\n \"callback_url\": \"http://example.com/moengage-callback\",\n \"emails\": [\n \"user1@example.com\"\n ]\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "Basic <encoded-value>")
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-{dc}.moengage.com/v2/custom-segments/file-segment/add-users")
.header("Content-Type", "<content-type>")
.header("Authorization", "Basic <encoded-value>")
.body("{\n \"name\": \"custom_segment_unique_name\",\n \"attribute_name\": \"unique_identifier\",\n \"attribute_type\": \"string\",\n \"file_url\": \"https://s3.amazonaws.com/Sample_GAIDs_add.csv\",\n \"callback_url\": \"http://example.com/moengage-callback\",\n \"emails\": [\n \"user1@example.com\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = '<content-type>'
request["Authorization"] = 'Basic <encoded-value>'
request.body = "{\n \"name\": \"custom_segment_unique_name\",\n \"attribute_name\": \"unique_identifier\",\n \"attribute_type\": \"string\",\n \"file_url\": \"https://s3.amazonaws.com/Sample_GAIDs_add.csv\",\n \"callback_url\": \"http://example.com/moengage-callback\",\n \"emails\": [\n \"user1@example.com\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"message": "File-segment user-add request accepted",
"success": true,
"cs_name": "custom_segment_unique_name"
}{
"title": "Invalid Request",
"description": "<message>"
}{
"title": "Authentication required",
"description": "<message>"
}{
"title": "Entity Not Found",
"description": "Custom segment not found with the given name: <custom_segment_unique_name>"
}{
"title": "Too Many Requests",
"description": "<appropriate message>"
}{
"title": "Internal Server Error"
}Add users to file segment
Adds a list of users from a CSV file to an existing file segment.
curl --request PUT \
--url https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: <content-type>' \
--data '
{
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs_add.csv",
"callback_url": "http://example.com/moengage-callback",
"emails": [
"user1@example.com"
]
}
'import requests
url = "https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users"
payload = {
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs_add.csv",
"callback_url": "http://example.com/moengage-callback",
"emails": ["user1@example.com"]
}
headers = {
"Content-Type": "<content-type>",
"Authorization": "Basic <encoded-value>"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': '<content-type>', Authorization: 'Basic <encoded-value>'},
body: JSON.stringify({
name: 'custom_segment_unique_name',
attribute_name: 'unique_identifier',
attribute_type: 'string',
file_url: 'https://s3.amazonaws.com/Sample_GAIDs_add.csv',
callback_url: 'http://example.com/moengage-callback',
emails: ['user1@example.com']
})
};
fetch('https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users', 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/v2/custom-segments/file-segment/add-users",
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([
'name' => 'custom_segment_unique_name',
'attribute_name' => 'unique_identifier',
'attribute_type' => 'string',
'file_url' => 'https://s3.amazonaws.com/Sample_GAIDs_add.csv',
'callback_url' => 'http://example.com/moengage-callback',
'emails' => [
'user1@example.com'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: <content-type>"
],
]);
$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/v2/custom-segments/file-segment/add-users"
payload := strings.NewReader("{\n \"name\": \"custom_segment_unique_name\",\n \"attribute_name\": \"unique_identifier\",\n \"attribute_type\": \"string\",\n \"file_url\": \"https://s3.amazonaws.com/Sample_GAIDs_add.csv\",\n \"callback_url\": \"http://example.com/moengage-callback\",\n \"emails\": [\n \"user1@example.com\"\n ]\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "Basic <encoded-value>")
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-{dc}.moengage.com/v2/custom-segments/file-segment/add-users")
.header("Content-Type", "<content-type>")
.header("Authorization", "Basic <encoded-value>")
.body("{\n \"name\": \"custom_segment_unique_name\",\n \"attribute_name\": \"unique_identifier\",\n \"attribute_type\": \"string\",\n \"file_url\": \"https://s3.amazonaws.com/Sample_GAIDs_add.csv\",\n \"callback_url\": \"http://example.com/moengage-callback\",\n \"emails\": [\n \"user1@example.com\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-{dc}.moengage.com/v2/custom-segments/file-segment/add-users")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = '<content-type>'
request["Authorization"] = 'Basic <encoded-value>'
request.body = "{\n \"name\": \"custom_segment_unique_name\",\n \"attribute_name\": \"unique_identifier\",\n \"attribute_type\": \"string\",\n \"file_url\": \"https://s3.amazonaws.com/Sample_GAIDs_add.csv\",\n \"callback_url\": \"http://example.com/moengage-callback\",\n \"emails\": [\n \"user1@example.com\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"message": "File-segment user-add request accepted",
"success": true,
"cs_name": "custom_segment_unique_name"
}{
"title": "Invalid Request",
"description": "<message>"
}{
"title": "Authentication required",
"description": "<message>"
}{
"title": "Entity Not Found",
"description": "Custom segment not found with the given name: <custom_segment_unique_name>"
}{
"title": "Too Many Requests",
"description": "<appropriate message>"
}{
"title": "Internal Server Error"
}Authorizations
Basic Authentication using your Workspace ID (as username) and Data API Key (as password) from the MoEngage Dashboard.
Headers
Select the file content type.
text/csv, application/csv, application/vnd.ms-excel, text/plain, application/octet-stream, binary/octet-stream Set the database from which the data is available (MOE-DBNAME).
Body
Details of the segment to update and the file URL of users to add.
Schema for updating an existing file segment (add, remove, replace users).
Name of the custom segment. Must be unique for creation.
Name of the user attribute to use as an identifier (e.g., 'ID', 'email').
The data type of the attribute_name.
string, double A public, downloadable URL to a single-column CSV file.
Callback URL to receive the result of segment processing.
List of email IDs to receive segment processing response.
Was this page helpful?