Skip to main content

Segments API

A segment is a saved audience definition — a filter over your contacts (attributes, custom fields, engagement history, loyalty traits) that campaigns, flows, and personalization can target. The saved-segment CRUD surface lives under the Contacts API; this page covers the top-level segment endpoints that operate on audiences without requiring you to save one first, plus AI-assisted segment discovery. Base path: /api/v1/segments (ad-hoc + AI endpoints below) and /api/v1/contacts/segments (saved-segment CRUD, membership, and its own GET /{id}/export.csv — see the Contacts API). Authentication: API key (X-API-Key) or session JWT.

AI auto-suggest

Unlike the description-driven segment builder (POST /contacts/segments/autopilot, which turns a sentence like “everyone who clicked the pricing page but didn’t book a demo” into a filter), auto-suggest takes no input — it reads your org’s own CDP event volume (top event names, contact tags, engagement histogram) and proposes up to 5 segments you probably haven’t created yet, each with a name, a one-line pitch, a rationale, and a ready-to-use filter. Nothing is persisted — the operator picks a suggestion to pre-fill the create-segment dialog.

Ad-hoc CSV export

GET /contacts/segments/{id}/export.csv already streams a saved segment’s membership as CSV. POST /segments/export.csv covers the case where you haven’t saved a segment yet — you have a filter (the same filter shape the segment builder and auto-suggest use) and just want the matching contacts as a one-off download, without persisting a segment or waiting for membership to materialize. Hard-capped at 50,000 rows per call (the optional limit in the body can set a lower cap). When the result set hits the cap, the response carries an X-Export-Truncated: true header so you know the file is partial — save the audience as a segment and use the paginated saved-segment export for a larger or recurring pull. POST /segments/from-clicks closes the loop from link engagement to audience: given a tracked short link (link_id) or every link in a campaign (campaign_id), it resolves the distinct contacts who clicked and materializes them as a static segment — no filter rules, just a point-in-time snapshot of “people who clicked this.” Useful for a targeted re-engagement send to exactly the people who showed interest. Because click activity is a point-in-time event rather than a live trait, the resulting segment does not auto-refresh — generate a fresh cohort to capture a later window. The request body must contain at least one of link_id or campaign_id, and accepts an optional window_days (1–365), name, and description.

Examples

POST /segments/auto-suggest

Request (all fields are optional — limit defaults to 5 and is clamped to 8):
Each returned suggestion carries name, description (a one-line, operator-facing pitch), rationale (why it is high-value for your data), and filters (a filter tree you can persist as-is). Every suggestion is validated against your contacts before the response — suggestions that would match nothing are dropped, and llm_dropped_count tells you how many were filtered out.
If the org has no usable CDP signal yet (zero contacts or zero events in the last 30 days), the endpoint skips the AI round-trip and responds with an empty list plus a hint:
Other failure modes are explicit error envelopes — 422 AI_PARSE_FAILED when the model output is not parseable, 502 AI_SUGGEST_FAILED when the suggestion call itself fails, and 503 SERVICE_UNAVAILABLE when auto-suggest is not enabled on the deployment. Retry on 502; on 422 and 503, fall back to the manual segment builder.

POST /segments/export.csv

Request — any filter tree the segment builder accepts, plus an optional per-call row cap and download filename:
A 200 response is the CSV itself (Content-Type: text/csv, Content-Disposition: attachment; filename="na-customers-opted-in-2026-08-25.csv"). Phone and email columns honour the caller’s role and reveal-context exactly as the dashboard does — a caller without reveal permission receives masked values.
An invalid filter (a non-allowlisted field, a mismatched operator, or a body that fails shape validation) returns a 400 envelope:
Two rate limits apply to this endpoint: a heavy export is capped at 5 requests per minute per tenant, and a generic per-key limit sits on top of that. On 429, wait for the window and retry with backoff; for pulls that routinely exceed the 50,000-row hard cap or the rate budget, persist the audience as a segment and page through GET /contacts/segments/{id}/export.csv instead.

POST /segments/from-clicks

Request — scope the cohort by link_id or campaign_id, optionally narrow to a recency window and name the segment:
On success the response is a 201 with the persisted segment and its materialized membership count:
Because the segment row now exists, every saved-segment surface applies to it — for example, to pull the cohort as CSV:
If no contacts have clicked the link(s) yet — or clicks exist but none are message-attributed back to a recipient contact — the endpoint returns a 422 instead of creating an empty segment:

Recipe: auto-suggest → saved segment → campaign target

The full loop, end to end:
  1. Get suggestions. POST /segments/auto-suggest and read data.suggestions. Each suggestion’s filters is a ready-to-persist filter definition.
  2. Pick one and persist it. Pass the suggestion’s filters to the saved-segment create endpoint with a name — membership materializes immediately on create, so the segment is usable without waiting for the refresh cycle:
  1. Use the returned segment id. Target it from a campaign audience, a flow trigger, or the personalization rule engine — anywhere a segment_id is accepted. A saved segment auto-refreshes (unless you created it from a click cohort, which is a fixed snapshot), so step 2 is done once and steps 1–3 can be repeated whenever you want fresh suggestions.
To sanity-check membership before committing the segment to a campaign, post the same filters body to POST /segments/export.csv and download the matching rows — that one-off export never persists anything.

SDK note

The Node SDK covers saved-segment CRUD (orbit.contacts.segments.list() / .create() / .get() over /contacts/segments). The three ad-hoc endpoints on this page — auto-suggest, ad-hoc export, and click cohorts — are invoked directly over HTTP as shown above; parse the CSV responses yourself or save the audience as a segment and use the SDK’s saved-segment surface.

See also

  • Contacts API — saved-segment CRUD, membership, and paginated export
  • Loyalty API — loyalty traits usable as segment filter conditions
  • Links API — the short links from-clicks resolves against