/api/admin/segments
Availability
Plan: Pro and Enterprise | Version: 4.13+
note
To use the admin API, you'll need to create and use an admin API token.
The segments API lets you create, read, update, and delete segments.
Get all segments
Retrieve all segments that exist in this Unleash instance. Returns a list of segment objects.
- HTTP
- cURL
- HTTPie
Retrieve all existing segments.
GET <unleash-url>/api/admin/segments
Authorization: <API-token>
content-type: application/json
Retrieve all existing segments.
curl -H "Content-Type: application/json" \
-H "Authorization: <API-token>" \
-X GET \
<unleash-url>/api/admin/segments
Retrieve all existing segments.
http GET \
<unleash-url>/api/admin/segments \
Authorization:<API-token> \
Example responses
200 OK
[
{
"id": 1,
"name": "my-segment",
"description": "a segment description",
"constraints": [],
"createdBy": "user@example.com",
"createdAt": "2022-04-01T14:02:25.491Z"
}
]
Create segment
Create a new segment with the specified configuration.
- HTTP
- cURL
- HTTPie
Create a new segment.
POST <unleash-url>/api/admin/segments
Authorization: <API-token>
content-type: application/json
{
"name": "my-segment",
"description": "a segment description",
"constraints": []
}
Create a new segment.
curl -H "Content-Type: application/json" \
-H "Authorization: <API-token>" \
-X POST \
-d '{
"name": "my-segment",
"description": "a segment description",
"constraints": []
}' \
<unleash-url>/api/admin/segments
Create a new segment.
echo '{
"name": "my-segment",
"description": "a segment description",
"constraints": []
}' \
| http POST \
<unleash-url>/api/admin/segments \
Authorization:<API-token>
Example responses
Payload structure
Use a JSON object with the following properties to create a new segment.
Property | Type | Required | Description | Example value |
---|---|---|---|---|
name | string | Yes | The name of the segment. | "mobile-users" |
description | string | No | A description of the segment. | "This segment is for users on mobile devices." |
constraints | list of constraint objects | Yes | The constraints in this segment. | [] |
Get segment by ID
Retrieves the segment with the specified ID.
- HTTP
- cURL
- HTTPie
Retrieve the segment with the provided ID.
GET <unleash-url>/api/admin/segments/<segment-id>
Authorization: <API-token>
content-type: application/json
Retrieve the segment with the provided ID.
curl -H "Content-Type: application/json" \
-H "Authorization: <API-token>" \
-X GET \
<unleash-url>/api/admin/segments/<segment-id>
Retrieve the segment with the provided ID.
http GET \
<unleash-url>/api/admin/segments/<segment-id> \
Authorization:<API-token> \
Example responses
Update an existing segment
Replace the data of the specified segment with the provided payload.
- HTTP
- cURL
- HTTPie
Update a segment with new data.
PUT <unleash-url>/api/admin/segments/<segment-id>
Authorization: <API-token>
content-type: application/json
{
"name": "my-segment",
"description": "this is a newly provided description.",
"constraints": []
}
Update a segment with new data.
curl -H "Content-Type: application/json" \
-H "Authorization: <API-token>" \
-X PUT \
-d '{
"name": "my-segment",
"description": "this is a newly provided description.",
"constraints": []
}' \
<unleash-url>/api/admin/segments/<segment-id>
Update a segment with new data.
echo '{
"name": "my-segment",
"description": "this is a newly provided description.",
"constraints": []
}' \
| http PUT \
<unleash-url>/api/admin/segments/<segment-id> \
Authorization:<API-token>