Create segment
curl --request POST \
--url https://api.emailr.dev/v1/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Active Users",
"description": "Users who opened an email in the last 30 days",
"type": "data_driven",
"conditions": {
"logic": "and",
"rules": [
{
"field": "properties.plan_type",
"operator": "equals",
"value": "premium"
}
]
},
"tags": [
"newsletter",
"vip"
]
}
'import requests
url = "https://api.emailr.dev/v1/segments"
payload = {
"name": "Active Users",
"description": "Users who opened an email in the last 30 days",
"type": "data_driven",
"conditions": {
"logic": "and",
"rules": [
{
"field": "properties.plan_type",
"operator": "equals",
"value": "premium"
}
]
},
"tags": ["newsletter", "vip"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Active Users',
description: 'Users who opened an email in the last 30 days',
type: 'data_driven',
conditions: {
logic: 'and',
rules: [{field: 'properties.plan_type', operator: 'equals', value: 'premium'}]
},
tags: ['newsletter', 'vip']
})
};
fetch('https://api.emailr.dev/v1/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.emailr.dev/v1/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' => 'Active Users',
'description' => 'Users who opened an email in the last 30 days',
'type' => 'data_driven',
'conditions' => [
'logic' => 'and',
'rules' => [
[
'field' => 'properties.plan_type',
'operator' => 'equals',
'value' => 'premium'
]
]
],
'tags' => [
'newsletter',
'vip'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.emailr.dev/v1/segments"
payload := strings.NewReader("{\n \"name\": \"Active Users\",\n \"description\": \"Users who opened an email in the last 30 days\",\n \"type\": \"data_driven\",\n \"conditions\": {\n \"logic\": \"and\",\n \"rules\": [\n {\n \"field\": \"properties.plan_type\",\n \"operator\": \"equals\",\n \"value\": \"premium\"\n }\n ]\n },\n \"tags\": [\n \"newsletter\",\n \"vip\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.emailr.dev/v1/segments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Active Users\",\n \"description\": \"Users who opened an email in the last 30 days\",\n \"type\": \"data_driven\",\n \"conditions\": {\n \"logic\": \"and\",\n \"rules\": [\n {\n \"field\": \"properties.plan_type\",\n \"operator\": \"equals\",\n \"value\": \"premium\"\n }\n ]\n },\n \"tags\": [\n \"newsletter\",\n \"vip\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.emailr.dev/v1/segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Active Users\",\n \"description\": \"Users who opened an email in the last 30 days\",\n \"type\": \"data_driven\",\n \"conditions\": {\n \"logic\": \"and\",\n \"rules\": [\n {\n \"field\": \"properties.plan_type\",\n \"operator\": \"equals\",\n \"value\": \"premium\"\n }\n ]\n },\n \"tags\": [\n \"newsletter\",\n \"vip\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "123e4567-e89b-12d3-a456-426614174000",
"organization_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"description": "<string>",
"type": "data_driven",
"conditions": {},
"tags": [
"newsletter",
"vip"
],
"created_by": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": "An error occurred",
"code": "VALIDATION_ERROR",
"details": "<unknown>"
}{
"error": "An error occurred",
"code": "VALIDATION_ERROR",
"details": "<unknown>"
}segments
Create segment
Create a new contact segment. For data-driven segments, conditions must be provided.
POST
/
v1
/
segments
Create segment
curl --request POST \
--url https://api.emailr.dev/v1/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Active Users",
"description": "Users who opened an email in the last 30 days",
"type": "data_driven",
"conditions": {
"logic": "and",
"rules": [
{
"field": "properties.plan_type",
"operator": "equals",
"value": "premium"
}
]
},
"tags": [
"newsletter",
"vip"
]
}
'import requests
url = "https://api.emailr.dev/v1/segments"
payload = {
"name": "Active Users",
"description": "Users who opened an email in the last 30 days",
"type": "data_driven",
"conditions": {
"logic": "and",
"rules": [
{
"field": "properties.plan_type",
"operator": "equals",
"value": "premium"
}
]
},
"tags": ["newsletter", "vip"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Active Users',
description: 'Users who opened an email in the last 30 days',
type: 'data_driven',
conditions: {
logic: 'and',
rules: [{field: 'properties.plan_type', operator: 'equals', value: 'premium'}]
},
tags: ['newsletter', 'vip']
})
};
fetch('https://api.emailr.dev/v1/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.emailr.dev/v1/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' => 'Active Users',
'description' => 'Users who opened an email in the last 30 days',
'type' => 'data_driven',
'conditions' => [
'logic' => 'and',
'rules' => [
[
'field' => 'properties.plan_type',
'operator' => 'equals',
'value' => 'premium'
]
]
],
'tags' => [
'newsletter',
'vip'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.emailr.dev/v1/segments"
payload := strings.NewReader("{\n \"name\": \"Active Users\",\n \"description\": \"Users who opened an email in the last 30 days\",\n \"type\": \"data_driven\",\n \"conditions\": {\n \"logic\": \"and\",\n \"rules\": [\n {\n \"field\": \"properties.plan_type\",\n \"operator\": \"equals\",\n \"value\": \"premium\"\n }\n ]\n },\n \"tags\": [\n \"newsletter\",\n \"vip\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.emailr.dev/v1/segments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Active Users\",\n \"description\": \"Users who opened an email in the last 30 days\",\n \"type\": \"data_driven\",\n \"conditions\": {\n \"logic\": \"and\",\n \"rules\": [\n {\n \"field\": \"properties.plan_type\",\n \"operator\": \"equals\",\n \"value\": \"premium\"\n }\n ]\n },\n \"tags\": [\n \"newsletter\",\n \"vip\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.emailr.dev/v1/segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Active Users\",\n \"description\": \"Users who opened an email in the last 30 days\",\n \"type\": \"data_driven\",\n \"conditions\": {\n \"logic\": \"and\",\n \"rules\": [\n {\n \"field\": \"properties.plan_type\",\n \"operator\": \"equals\",\n \"value\": \"premium\"\n }\n ]\n },\n \"tags\": [\n \"newsletter\",\n \"vip\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "123e4567-e89b-12d3-a456-426614174000",
"organization_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"description": "<string>",
"type": "data_driven",
"conditions": {},
"tags": [
"newsletter",
"vip"
],
"created_by": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": "An error occurred",
"code": "VALIDATION_ERROR",
"details": "<unknown>"
}{
"error": "An error occurred",
"code": "VALIDATION_ERROR",
"details": "<unknown>"
}Authorizations
API key authentication. Use your API key as the bearer token.
Body
application/json
Minimum string length:
1Example:
"Active Users"
Example:
"Users who opened an email in the last 30 days"
Segment type: 'manual' for static segments, 'data_driven' for dynamic filter-based segments
Available options:
manual, data_driven Example:
"data_driven"
Filter conditions for data-driven segments. Required when type is 'data_driven'.
Show child attributes
Show child attributes
Example:
{ "logic": "and", "rules": [ { "field": "properties.plan_type", "operator": "equals", "value": "premium" } ] }
Tags for categorization. Lowercase, max 50 chars each, max 20 tags.
Example:
["newsletter", "vip"]
Response
Segment created
Example:
"123e4567-e89b-12d3-a456-426614174000"
Segment type: 'manual' or 'data_driven'
Available options:
manual, data_driven Example:
"data_driven"
Show child attributes
Show child attributes
Tags for categorization.
Example:
["newsletter", "vip"]
⌘I