Skip to main content

Segments API

Segments endpoints exposed by the Devotel CPaaS API Base path: /api/v1 Endpoint count: 4

title: “AI-proposed segments and ad-hoc exports” description: “Describe an audience in plain language and get structured rules plus a live preview; or pull an unsaved FilterAst out to CSV without persisting a segment.”

AI-proposed segments and ad-hoc exports

These two operations serve the campaign desk side of the contacts module — the screen where marketers shape an audience by hand or by prompt and take the rows out. Use the autopilot to translate a natural-language prompt into rules plus a live match-count preview in one round-trip; use the export to pull an unsaved FilterAst into a CSV without persisting anything. Build from a description. POST /api/v1/contacts/segments/autopilot returns operator (the boolean the LLM chose), rules (the flat list the dashboard renders), filters (the normalized FilterAst the segmentation engine consumes — so the following “Create” click needs no second translation), and preview (match_count + sample_contacts). The Node SDK has no typed helper for this surface; use the generic request() escape hatch shown below — it keeps the { data, meta } envelope identical. Request
The proposed rules are constrained to the segmentation engine’s allowlisted fields and engine-dry-run validated before the preview, so a 422 means “try rephrasing” (the response echoes the first 500 chars of the LLM’s raw output). A 503 SERVICE_UNAVAILABLE means the AI backend is not configured for the platform — fall back to the manual segment builder. Both endpoints require the contacts:write scope (owner / admin / developer). Export an unsaved audience. POST /api/v1/segments/export.csv resolves the same FilterAst shape the manual builder produces — a single condition or a nested AND / OR group — live against the tenant’s contacts and returns the matched rows as an RFC-4180 CSV download. PII columns (phone, email) honor the caller’s role and reveal context exactly as the dashboard renders them. A truncated export (past the 50,000-row ceiling, limit-clamped below it) sets the X-Export-Truncated: true response header so you know you got a partial pull.

SDK surface bridge — Translate a natural-language audience into engine-validated rules, or export an unsaved FilterAst out to CSV — both reachable through the SDK escape hatch.

These three tabs mirror SDK status and coverage. Python fronts client.request, Go fronts client.Request, and TS fronts fetch-TS — each with the sandbox key.

Describe a segment (AI autopilot)

Export an ad-hoc audience as CSV




Build a segment from a natural-language description (AI)

POST /api/v1/contacts/segments/autopilot
Translate a natural-language audience description into structured Orbit segment rules and return them together with a live preview match-count and sample contacts, in a single round-trip. The proposed rules are constrained to the segmentation engine’s allowlisted fields, validated with a dry-run before the preview, and returned in both the dashboard’s flat rule shape and the normalised FilterAst the engine consumes — so the operator’s “Create” click needs no second translation. Requires the contacts:write scope (owner / admin / developer). Returns 503 SERVICE_UNAVAILABLE when the AI backend is not configured for the platform; callers should fall back to the manual segment builder.
string
Stripe-style idempotency token. Pass a stable, client-generated value (1-255 chars) to dedupe retries on transient timeouts. The same key+credential+path replays the original response for 24h on 2xx (5min on 4xx, 30s on 5xx). Returns 409 if a concurrent request with the same key is already in flight; replayed responses include the Idempotency-Replay: true response header.
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.
string
required
Natural-language description of the audience to build (e.g. “customers in Germany who opened an email in the last 30 days”). The handler asks the LLM to translate it into structured segment rules constrained to the segmentation engine’s allowlisted fields.
integer
Maximum number of sample contacts returned in preview.sample_contacts. Keeps the payload bounded — the dashboard renders only the first 10.

Auto-suggest segments

POST /api/v1/segments/auto-suggest
string
Stripe-style idempotency token. Pass a stable, client-generated value (1-255 chars) to dedupe retries on transient timeouts. The same key+credential+path replays the original response for 24h on 2xx (5min on 4xx, 30s on 5xx). Returns 409 if a concurrent request with the same key is already in flight; replayed responses include the Idempotency-Replay: true response header.
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.

Export an ad-hoc audience as CSV

POST /api/v1/segments/export.csv
Resolve an ad-hoc audience — an unsaved segment filter AST, the same shape the segment builder and POST /api/v1/segments/auto-suggest produce — live against the tenant’s contacts and download the matched rows as an RFC-4180 CSV attachment, without first persisting or materialising a segment. PII columns (phone, email) honour the caller’s role + reveal context. Requires the contacts:write scope (owner / admin / developer). Hard-capped at 50,000 rows; a truncated export sets the X-Export-Truncated: true response header. The saved-segment equivalent is GET /api/v1/contacts/segments/{id}/export.csv.
string
Stripe-style idempotency token. Pass a stable, client-generated value (1-255 chars) to dedupe retries on transient timeouts. The same key+credential+path replays the original response for 24h on 2xx (5min on 4xx, 30s on 5xx). Returns 409 if a concurrent request with the same key is already in flight; replayed responses include the Idempotency-Replay: true response header.
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.

POST /api/v1/segments/from-clicks
Resolve the recipient contacts that clicked a tracked short link (link_id) or any link in a campaign (campaign_id) and materialise them as a static contact segment for retargeting. Click engagement is captured as a point-in-time snapshot (auto_refresh = false). Optionally narrow to a recency window with window_days. Requires the contacts:write scope (owner / admin / developer).
string
Stripe-style idempotency token. Pass a stable, client-generated value (1-255 chars) to dedupe retries on transient timeouts. The same key+credential+path replays the original response for 24h on 2xx (5min on 4xx, 30s on 5xx). Returns 409 if a concurrent request with the same key is already in flight; replayed responses include the Idempotency-Replay: true response header.
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.