Segments
CRUD for rule-based user segments and on-demand re-evaluation.
Segments are JSON rule trees applied against app_users + engagement_events. They're re-evaluated by a Temporal cron workflow every 15 minutes; the /evaluate endpoint triggers an immediate out-of-band re-evaluation.
Source: apps/api/src/routes/admin/segments.ts. Shared rule types: packages/shared/src/segment-rules.ts.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /admin/projects/:projectId/segments | Create a segment. |
| GET | /admin/projects/:projectId/segments | List segments (system segments first). |
| GET | /admin/projects/:projectId/segments/:segmentId | Fetch a segment. |
| PATCH | /admin/projects/:projectId/segments/:segmentId | Update a non-system segment. |
| DELETE | /admin/projects/:projectId/segments/:segmentId | Delete a non-system segment. |
| POST | /admin/projects/:projectId/segments/:segmentId/evaluate | Kick off an out-of-band re-evaluation. |
Rule shape
Operators: eq, neq, gt, gte, lt, lte, contains, not_contains, exists, not_exists, within, not_within.
POST /admin/projects/:projectId/segments
Request
| Field | Type | Required |
|---|---|---|
name | string | yes |
description | string | no |
rules | SegmentRules object | yes |
Response 201
Errors
500 CREATE_FAILED.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/segmentscurl -X POST 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/segments'Curl:
GET /admin/projects/:projectId/segments
List segments. System segments (created by provisioning) are returned first.
Response 200
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/segmentscurl -X GET 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/segments'Curl:
GET /admin/projects/:projectId/segments/:segmentId
Response 200
Errors
404 NOT_FOUND.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7Dcurl -X GET 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7D'Curl:
PATCH /admin/projects/:projectId/segments/:segmentId
Update name, description, and/or rules. Only keys present in the body are changed — a PATCH never nulls out omitted keys.
Errors
403 SYSTEM_SEGMENT— system segments are read-only.404 NOT_FOUND.500 UPDATE_FAILED.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7Dcurl -X PATCH 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7D'Curl:
DELETE /admin/projects/:projectId/segments/:segmentId
Response 200
Errors
403 SYSTEM_SEGMENT.500 DELETE_FAILED.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7Dcurl -X DELETE 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7D'Curl:
POST /admin/projects/:projectId/segments/:segmentId/evaluate
Start a SEGMENT_EVALUATION Temporal workflow for a single segment. Returns immediately — poll the segment row to see last_evaluated_at advance.
Response 200
Errors
404 NOT_FOUND.500 EVALUATE_FAILED.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7D/evaluatecurl -X POST 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/segments/%7B%7BsegmentId%7D%7D/evaluate'Curl: