API Reference
Segments Create dynamic audience segments with rule-based membership and trigger recomputation.
Segments are dynamic groups of contacts defined by rules. Membership is computed automatically based on contact properties and event history. Use segments to target specific audiences in campaigns and sequences.
Creates a new segment with the specified rules.
Field Type Required Description namestring Yes Human-readable name for the segment. rulesobject Yes Rule definition that determines membership. See Rule format .
Returns the created segment.
{
"id" : "seg_01H9..." ,
"name" : "Active Pro Users" ,
"rules" : {
"operator" : "and" ,
"conditions" : [
{ "field" : "properties.plan" , "op" : "eq" , "value" : "pro" },
{ "field" : "events.login" , "op" : "occurred" , "within" : "30d" }
]
},
"memberCount" : 0 ,
"computedAt" : null ,
"createdAt" : "2025-09-15T10:00:00.000Z" ,
"updatedAt" : "2025-09-15T10:00:00.000Z"
}
Code Description VALIDATION_ERRORMissing name or invalid rules.
curl -X POST https://api.kraiter.com/api/segments \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Active Pro Users",
"rules": {
"operator": "and",
"conditions": [
{ "field": "properties.plan", "op": "eq", "value": "pro" },
{ "field": "events.login", "op": "occurred", "within": "30d" }
]
}
}'
const segment = await kraiter.segments. create ({
name: "Active Pro Users" ,
rules: {
operator: "and" ,
conditions: [
{ field: "properties.plan" , op: "eq" , value: "pro" },
{ field: "events.login" , op: "occurred" , within: "30d" },
],
},
});
Returns a paginated list of segments.
Parameter Type Default Description cursorstring — Pagination cursor. limitnumber 20 Number of segments to return (max 100).
curl "https://api.kraiter.com/api/segments?limit=10" \
-H "Authorization: Bearer YOUR_API_KEY"
const segments = await kraiter.segments. list ({ limit: 10 });
Returns a single segment including its rules and membership count.
Parameter Type Description idstring The segment ID.
Code Description NOT_FOUNDNo segment with this ID exists.
curl https://api.kraiter.com/api/segments/seg_01H9... \
-H "Authorization: Bearer YOUR_API_KEY"
const segment = await kraiter.segments. get ( "seg_01H9..." );
Updates a segment's name or rules. Changing the rules does not automatically recompute membership — call Compute segment to trigger recomputation.
Parameter Type Description idstring The segment ID.
Field Type Required Description namestring No New name for the segment. rulesobject No New rule definition.
curl -X PATCH https://api.kraiter.com/api/segments/seg_01H9... \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"rules": {
"operator": "and",
"conditions": [
{ "field": "properties.plan", "op": "in", "value": ["pro", "enterprise"] },
{ "field": "events.login", "op": "occurred", "within": "7d" }
]
}
}'
const segment = await kraiter.segments. update ( "seg_01H9..." , {
rules: {
operator: "and" ,
conditions: [
{ field: "properties.plan" , op: "in" , value: [ "pro" , "enterprise" ] },
{ field: "events.login" , op: "occurred" , within: "7d" },
],
},
});
Permanently deletes a segment. Campaigns referencing this segment are not affected but will no longer resolve its members.
Returns 204 No Content on success.
Code Description NOT_FOUNDNo segment with this ID exists.
curl -X DELETE https://api.kraiter.com/api/segments/seg_01H9... \
-H "Authorization: Bearer YOUR_API_KEY"
await kraiter.segments. delete ( "seg_01H9..." );
GET /api/segments/:id/members
Returns the contacts that currently belong to this segment.
Parameter Type Description idstring The segment ID.
Parameter Type Default Description cursorstring — Pagination cursor. limitnumber 20 Number of members to return (max 100).
{
"data" : [
{
"id" : "cnt_01H8MZXK..." ,
"email" : "alice@example.com" ,
"properties" : { "plan" : "pro" },
"joinedAt" : "2025-09-15T10:30:00.000Z"
}
],
"nextCursor" : null
}
curl "https://api.kraiter.com/api/segments/seg_01H9.../members?limit=50" \
-H "Authorization: Bearer YOUR_API_KEY"
const members = await kraiter.segments. listMembers ( "seg_01H9..." , {
limit: 50 ,
});
POST /api/segments/:id/compute
Triggers a recomputation of segment membership. This evaluates the segment rules against all contacts and updates the member list. Computation runs asynchronously — the response confirms the job has been queued.
Parameter Type Description idstring The segment ID.
{
"segmentId" : "seg_01H9..." ,
"status" : "computing" ,
"queuedAt" : "2025-09-15T15:00:00.000Z"
}
Code Description NOT_FOUNDNo segment with this ID exists.
curl -X POST https://api.kraiter.com/api/segments/seg_01H9.../compute \
-H "Authorization: Bearer YOUR_API_KEY"
const result = await kraiter.segments. compute ( "seg_01H9..." );
Segment rules use a tree structure with logical operators and conditions.
Operator Description andAll conditions must be true. orAt least one condition must be true.
Prefix Description Example properties.*Contact property value. properties.planevents.*Event occurrence. events.purchase_completed
Operator Description Applies to eqEquals Properties neqNot equals Properties gtGreater than Properties (numeric) gteGreater than or equal Properties (numeric) ltLess than Properties (numeric) lteLess than or equal Properties (numeric) inValue is in list Properties containsString contains Properties (string) occurredEvent has occurred Events not_occurredEvent has not occurred Events
Event conditions support a within field to restrict the time window:
7d — within the last 7 days
30d — within the last 30 days
90d — within the last 90 days