Syncing segment membership
Create the segment in the Toggly dashboard and attach it to a targeting rule. Your backend then adds and removes identifiers with a Backend application key. Client SDKs only evaluate the published list; they never hold that key.
Flow
- In the dashboard, create a segment (for example
Beta Testers) and add it to a feature’s Targeting filter as Users or Groups. - Store a Backend application key on the server that already evaluates flags. Do not put it in a browser or mobile binary.
- Call
https://app.toggly.io/api/v2/segmentsto add, remove, or replace identifiers (see Segment membership API). - Wait for definitions to republish. Toggly copies list members into the flag payload. SDKs pick this up on their next definitions refresh (typically a few minutes, depending on cache TTL).
- Evaluate as usual with the user or group identity. Membership is true when that identity is in the published list.
sequenceDiagram
participant Backend as YourBackend
participant Api as app.toggly.io
participant Index as Definitions
participant Sdk as EvaluatingSDK
Backend->>Api: Backend key, add or remove ids
Api->>Api: Update ApplicationList
Index->>Index: Inline ids into targeting filters
Sdk->>Sdk: Next refresh evaluates the new set
What stays in the dashboard
- Creating, renaming, or deleting a segment
- Attaching a segment to a feature
- Team-wide management with OAuth client credentials
What the Backend key can do
- List segments it is allowed to touch
- Page identifiers
- Add, remove, or replace identifiers on those lists
A key restricted to an environment cannot change app-level lists (lists with no environment). Frontend and Mobile keys are rejected.
Evaluation lag
A successful write does not change in-process evaluation until the definitions index runs and the SDK refreshes. Do not treat HTTP 200 as “this user is targeted on the next request.”
SDK clients
Usage lives on the library page, not a combined language dump:
- Node.js · NestJS · Next.js server · Nuxt server · React Router server · SvelteKit · Astro · Gatsby · Electron main
- .NET · Java · Python · PHP · Go · Ruby · Rust · Elixir
Browser, mobile, and CSS packages only evaluate the published list.