Create a segment
POST /segments
Name an audience, optionally defined by a filter over your contacts.
Body
namestringRequiredUp to 200 characters, unique among live segments.
filterobject | null{ all | any | not: [ … ] }over{ field, op, value }and{ topic, subscription }conditions. Omit it for a segment with explicit membership only.
Request
curl -X POST "https://api.rasket.com/segments" \
-H "Authorization: Bearer $RASKET_API_KEY" \
-H "User-Agent: acme-billing/1.0" \
-H "Content-Type: application/json" \
-d '{
"name": "Trial accounts",
"filter": {
"all": [
{
"field": "properties.plan",
"op": "eq",
"value": "trial"
},
{
"field": "created_at",
"op": "gte",
"value": "2026-09-01T00:00:00Z"
}
]
}
}'const response = await fetch("https://api.rasket.com/segments", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.RASKET_API_KEY}`,
"User-Agent": "acme-billing/1.0",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Trial accounts",
filter: {
all: [
{
field: "properties.plan",
op: "eq",
value: "trial"
},
{
field: "created_at",
op: "gte",
value: "2026-09-01T00:00:00Z"
}
]
}
}),
});
const { id } = await response.json();import os
import requests
response = requests.post(
"https://api.rasket.com/segments",
headers={
"Authorization": f"Bearer {os.environ['RASKET_API_KEY']}",
"User-Agent": "acme-billing/1.0",
},
json={
"name": "Trial accounts",
"filter": {
"all": [
{
"field": "properties.plan",
"op": "eq",
"value": "trial"
},
{
"field": "created_at",
"op": "gte",
"value": "2026-09-01T00:00:00Z"
}
]
}
},
)
id = response.json()["id"]Response 201
{
"object": "segment",
"id": "78261eea-8f8b-4381-83c6-79fa7120f1cf"
}- The filter is checked against your contact properties when the segment is created: an undeclared property, or an operator that does not suit its type, is
422 validation_errorwith oneerrors[]entry per condition. - Membership is evaluated when it is read and when a broadcast is sent, never stored — a contact that starts matching is in the segment from that moment.