Kraiter
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.

Create segment

POST /api/segments

Creates a new segment with the specified rules.

Request body

FieldTypeRequiredDescription
namestringYesHuman-readable name for the segment.
rulesobjectYesRule definition that determines membership. See Rule format.

Response

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"
}

Errors

CodeDescription
VALIDATION_ERRORMissing name or invalid rules.

Examples

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" },
    ],
  },
});

List segments

GET /api/segments

Returns a paginated list of segments.

Query parameters

ParameterTypeDefaultDescription
cursorstringPagination cursor.
limitnumber20Number of segments to return (max 100).

Examples

curl "https://api.kraiter.com/api/segments?limit=10" \
  -H "Authorization: Bearer YOUR_API_KEY"
const segments = await kraiter.segments.list({ limit: 10 });

Get segment

GET /api/segments/:id

Returns a single segment including its rules and membership count.

Path parameters

ParameterTypeDescription
idstringThe segment ID.

Errors

CodeDescription
NOT_FOUNDNo segment with this ID exists.

Examples

curl https://api.kraiter.com/api/segments/seg_01H9... \
  -H "Authorization: Bearer YOUR_API_KEY"
const segment = await kraiter.segments.get("seg_01H9...");

Update segment

PATCH /api/segments/:id

Updates a segment's name or rules. Changing the rules does not automatically recompute membership — call Compute segment to trigger recomputation.

Path parameters

ParameterTypeDescription
idstringThe segment ID.

Request body

FieldTypeRequiredDescription
namestringNoNew name for the segment.
rulesobjectNoNew rule definition.

Examples

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" },
    ],
  },
});

Delete segment

DELETE /api/segments/:id

Permanently deletes a segment. Campaigns referencing this segment are not affected but will no longer resolve its members.

Response

Returns 204 No Content on success.

Errors

CodeDescription
NOT_FOUNDNo segment with this ID exists.

Examples

curl -X DELETE https://api.kraiter.com/api/segments/seg_01H9... \
  -H "Authorization: Bearer YOUR_API_KEY"
await kraiter.segments.delete("seg_01H9...");

List segment members

GET /api/segments/:id/members

Returns the contacts that currently belong to this segment.

Path parameters

ParameterTypeDescription
idstringThe segment ID.

Query parameters

ParameterTypeDefaultDescription
cursorstringPagination cursor.
limitnumber20Number of members to return (max 100).

Response

{
  "data": [
    {
      "id": "cnt_01H8MZXK...",
      "email": "alice@example.com",
      "properties": { "plan": "pro" },
      "joinedAt": "2025-09-15T10:30:00.000Z"
    }
  ],
  "nextCursor": null
}

Examples

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,
});

Compute segment

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.

Path parameters

ParameterTypeDescription
idstringThe segment ID.

Response

{
  "segmentId": "seg_01H9...",
  "status": "computing",
  "queuedAt": "2025-09-15T15:00:00.000Z"
}

Errors

CodeDescription
NOT_FOUNDNo segment with this ID exists.

Examples

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...");

Rule format

Segment rules use a tree structure with logical operators and conditions.

Operators

OperatorDescription
andAll conditions must be true.
orAt least one condition must be true.

Condition fields

PrefixDescriptionExample
properties.*Contact property value.properties.plan
events.*Event occurrence.events.purchase_completed

Comparison operators

OperatorDescriptionApplies to
eqEqualsProperties
neqNot equalsProperties
gtGreater thanProperties (numeric)
gteGreater than or equalProperties (numeric)
ltLess thanProperties (numeric)
lteLess than or equalProperties (numeric)
inValue is in listProperties
containsString containsProperties (string)
occurredEvent has occurredEvents
not_occurredEvent has not occurredEvents

Time window

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