Create Segment
Create a new segment or cohort to save filter combinations and track specific audience groups.
Endpoint
POST /api/websites/{websiteId}/segments
Bearer token for authentication
Path Parameters
Request Body
Segment type: segment or cohort
Segment name (max 200 characters)
Segment configuration parameters. Structure varies based on segment type and use case.
For audience segments, you can include filter criteria:{
"filters": {
"device": "mobile",
"country": "US"
}
}
For cohorts, you can include time-based grouping:{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}
Response
Segment configuration parameters
ISO 8601 timestamp of creation
Example Request
curl -X POST "https://your-umami-instance.com/api/websites/550e8400-e29b-41d4-a716-446655440000/segments" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"type": "segment",
"name": "Mobile Users from US",
"parameters": {
"filters": {
"device": "mobile",
"country": "US"
}
}
}'
Example Response
{
"id": "770e8400-e29b-41d4-a716-446655440001",
"websiteId": "550e8400-e29b-41d4-a716-446655440000",
"type": "segment",
"name": "Mobile Users from US",
"parameters": {
"filters": {
"device": "mobile",
"country": "US"
}
},
"createdAt": "2024-03-15T09:20:00.000Z"
}
You must have update permissions for the website to create segments. The parameters object structure is flexible and can contain any valid JSON.