Files
unleash/website/docs/api/admin/segments.mdx
T
2022-04-01 16:04:10 +02:00

86 lines
1.8 KiB
Plaintext

---
title: /api/admin/segments
---
import ApiRequest from '@site/src/components/ApiRequest'
export const basePath = "api/admin/segments"
export const path = (p) => `api/admin/segments/${p}`
:::info Availability
The segments API is available to Pro and Enterprise users from Unleash 4.10.
:::
:::note
To use the admin API, you'll need to [create and use an admin API token](../../user_guide/token.md).
:::
The segments API lets you create, read, update, and delete [segments](../../reference/segments.mdx). All payload
## Get all segments
Retrieve all segments that exist in this Unleash instance. Returns a list of [segment objects](#isegment).
<ApiRequest verb="Get" url={basePath} title="Retrieve all existing segments."/>
<details open>
<summary>Example responses</summary>
### 200 OK
``` json
[
{
"id": 1,
"name": "my-segment",
"description": "a segment description",
"constraints": [],
"createdBy": "user id",
"createdAt": "2022-04-01T14:02:25.491Z"
}
]
```
</details>
### Create segment: `POST /`
### Get segment by id: `GET /:id`
### Update segment by id: `PUT /:id`
### Delete segment by id: `DELETE /:id`
### List strategies that use a specific segment: `GET /:id/strategies`
### List segments applied to a specific strategy: `GET /strategies/:strategyId`
### Replace activation strategy segments `POST /strategies/:strategyId`
## Types
### `ISegment`: segment interface {#isegment}
``` ts
export interface ISegment {
id: number;
name: string;
description?: string;
constraints: IConstraint[];
createdBy?: string;
createdAt: Date;
}
```
### `IConstraint`: constraint interface {#iconstraint}
```ts
export interface IConstraint {
contextName: string;
operator: string;
values?: string[];
value?: string;
inverted?: boolean;
caseInsensitive?: boolean;
}
```