Skip to main content

Create Segment

Create a segment from a set of rules. A segment is a dynamic audience: the contacts that currently match its rules. Use its id in the segment_ids of a campaign.

The members are computed in the background. The segment is returned with status: "processing" and becomes "ready" once they are, usually within a few minutes. Poll Get Segment to see it change.

Endpoint​

POST /segments

Returns: 201 Created

Headers​

HeaderValueRequired
AuthorizationBearer <your-api-key>Yes
Content-Typeapplication/jsonYes

Body Parameters​

ParameterTypeRequiredDescription
namestringYesSegment name. Max 100 characters.
descriptionstringNoOptional description. Max 500 characters.
filterobjectYesThe rules a contact must match. See Segment Filters.

An organization can hold up to 500 segments.

For ready-made filters (engaged subscribers, lapsed customers, birthdays and more), see Common segments.

Response​

{
"id": "01957e3a-4b5c-7d8e-9f0a-1b2c3d4e5f6a",
"name": "VIP customers",
"description": "Opened 3+ emails in the last 90 days",
"status": "processing",
"filter": {
"type": "group",
"operator": "and",
"conditions": [
{
"type": "engagement_count",
"channel": "email",
"action": "opened",
"operator": "greater_than_or_equal",
"value": 3,
"time_window": { "value": 90, "unit": "days" }
},
{ "type": "channel_status", "channel": "email", "consent": "subscribed" }
]
},
"contact_count": null,
"counted_at": null,
"created_at": "2026-03-08T12:00:00.000Z",
"updated_at": "2026-03-08T12:00:00.000Z"
}

See List Segments for the field reference.


Examples​

curl -X POST "https://api.arsel.sa/v1/segments" \
-H "Authorization: Bearer $ARSEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "VIP customers",
"description": "Opened 3+ emails in the last 90 days",
"filter": {
"type": "group",
"operator": "and",
"conditions": [
{
"type": "engagement_count",
"channel": "email",
"action": "opened",
"operator": "greater_than_or_equal",
"value": 3,
"time_window": {
"value": 90,
"unit": "days"
}
},
{
"type": "channel_status",
"channel": "email",
"consent": "subscribed"
}
]
}
}'

Create, then wait until it is ready​

A new segment is processing until its members are computed. To use it straight away, for example to list its contacts, poll until status is ready.

async function arsel(path, { method = "GET", body } = {}) {
const response = await fetch(`https://api.arsel.sa/v1${path}`, {
method,
headers: {
Authorization: `Bearer ${process.env.ARSEL_API_KEY}`,
"Content-Type": "application/json",
},
body: body && JSON.stringify(body),
});
const data = await response.json();
if (!response.ok) throw new Error(`${data.name}: ${data.message}`);
return data;
}

const created = await arsel("/segments", {
method: "POST",
body: {
name: "Lapsed customers",
filter: {
type: "group",
operator: "and",
conditions: [
{ type: "event", event_name: "order_placed" },
{
type: "event",
event_name: "order_placed",
time_window: { value: 90, unit: "days" },
negate: true,
},
],
},
},
});

let segment = created;
while (segment.status === "processing") {
await new Promise((resolve) => setTimeout(resolve, 5000));
segment = await arsel(`/segments/${created.id}`);
}

const members = await arsel(`/contacts?segment_id=${created.id}&limit=100`);
console.log(segment.contact_count, members.data.length);

Error Responses​

{
"status_code": 422,
"name": "validation_error",
"message": "Invalid filter: conditions.0.operator: \"created_at\" does not accept the operator \"contains\""
}