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 . descriptionstring No Optional description of the segment. enabledboolean No Whether the segment is active. Defaults to true.
Returns the created segment.
{
"segmentId" : "seg_01H9..." ,
"name" : "Active Pro Users" ,
"description" : null ,
"rules" : {
"operator" : "and" ,
"conditions" : [
{ "type" : "property" , "field" : "plan" , "operator" : "equals" , "value" : "pro" },
{ "type" : "derived" , "field" : "totalOpens" , "operator" : "greaterThan" , "value" : 0 }
]
},
"enabled" : true ,
"memberCount" : 0 ,
"dependsOn" : [],
"dependedBy" : [],
"version" : "01H9..." ,
"lastComputedAt" : null ,
"createdAt" : "2025-09-15T10:00:00.000Z" ,
"updatedAt" : "2025-09-15T10:00:00.000Z"
}
Code Description VALIDATION_ERRORMissing name or invalid rules. CIRCULAR_DEPENDENCYA segment condition would create a cycle between segments.
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": [
{ "type": "property", "field": "plan", "operator": "equals", "value": "pro" },
{ "type": "derived", "field": "totalOpens", "operator": "greaterThan", "value": 0 }
]
}
}'
const segment = await kraiter.segments. create ({
name: "Active Pro Users" ,
rules: {
operator: "and" ,
conditions: [
{ type: "property" , field: "plan" , operator: "equals" , value: "pro" },
{ type: "derived" , field: "totalOpens" , operator: "greaterThan" , value: 0 },
],
},
});
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 SEGMENT_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. descriptionstring No New description. enabledboolean No Enable or disable the segment.
At least one field must be provided.
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": [
{ "type": "property", "field": "plan", "operator": "includes", "value": ["pro", "enterprise"] },
{ "type": "derived", "field": "inactiveDays", "operator": "lessThan", "value": 7 }
]
}
}'
const segment = await kraiter.segments. update ( "seg_01H9..." , {
rules: {
operator: "and" ,
conditions: [
{ type: "property" , field: "plan" , operator: "includes" , value: [ "pro" , "enterprise" ] },
{ type: "derived" , field: "inactiveDays" , operator: "lessThan" , value: 7 },
],
},
});
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 SEGMENT_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 membership records for contacts that currently belong to this segment. Each record identifies the contact by contactId — hydrate full contact details with the Contacts API if needed.
Parameter Type Description idstring The segment ID.
Parameter Type Default Description cursorstring — Pagination cursor. limitnumber — Number of members to return (max 1000).
{
"items" : [
{
"contactId" : "cnt_01H8MZXK..." ,
"isMember" : true ,
"computedAt" : "2025-09-15T10:30:00.000Z" ,
"version" : "01H9..."
}
],
"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
Recomputes segment membership by evaluating the rules against every contact and updating the member list. This runs synchronously and returns counts once complete. It can be expensive for large tenants and is rate-limited to roughly once per minute per segment.
Parameter Type Description idstring The segment ID.
{
"segmentId" : "seg_01H9..." ,
"processed" : 1240 ,
"changed" : 37
}
Field Type Description processednumber Number of contacts evaluated. changednumber Number of contacts whose membership changed.
Code Description SEGMENT_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 are a recursive tree. A rule node has a logical operator and a conditions array; each entry in conditions is either a leaf condition or a nested rule node, so you can build arbitrarily deep boolean expressions.
{
"operator" : "and" ,
"conditions" : [
{ "type" : "property" , "field" : "plan" , "operator" : "equals" , "value" : "pro" },
{
"operator" : "or" ,
"conditions" : [
{ "type" : "derived" , "field" : "totalClicks" , "operator" : "greaterThan" , "value" : 0 },
{ "type" : "segment" , "segmentId" : "seg_vip" , "operator" : "memberOf" }
]
}
]
}
Operator Description andAll conditions must be true. orAt least one condition must be true. notThe conditions must be false.
Every leaf condition has a type that selects which contact data it reads:
Type Shape Reads property{ type, field, operator, value }contact.properties.<field> (your custom properties).derived{ type, field, operator, value }contact.derived.<field> (system-computed engagement fields such as totalOpens, totalClicks, inactiveDays, lastEventAt).segment{ type, segmentId, operator }Membership in another segment.
Used by property and derived conditions:
Operator Description equals / notEqualsEquality comparison. greaterThan / lessThanNumeric comparison. greaterOrEqual / lessOrEqualNumeric comparison (inclusive). contains / notContainsSubstring check on a string value. startsWith / endsWithString prefix / suffix check. includes / notIncludesArray membership (does the field/value contain the given item). includesAll / includesAnyArray contains all / any of the given items. exists / notExistsWhether the field is present.
Used by segment conditions:
Operator Description memberOfContact is a member of the referenced segment. notMemberOfContact is not a member of the referenced segment.