---
title: "Create a new segment"
method: POST
path: "/api/admin/segments"
tags: ["Segments"]
---

# Create a new segment

`POST /api/admin/segments`

Creates a new segment using the payload provided

## Request body

- UpsertSegmentSchema — Data used to create or update a segment
  - `name` string, required — The name of the segment
  - `description` string, nullable — A description of what the segment is for
  - `project` string, nullable — The project the segment belongs to if any.
  - `constraints` ConstraintSchema[], required — The list of constraints that make up this segment
    - `contextName` string, required — The name of the context field that this constraint should apply to.
    - `operator` 'NOT_IN' | 'IN' | 'STR_ENDS_WITH' | 'STR_STARTS_WITH' | 'STR_CONTAINS' | 'NUM_EQ' | 'NUM_GT' | 'NUM_GTE' | 'NUM_LT' | 'NUM_LTE' | 'DATE_AFTER' | 'DATE_BEFORE' | 'SEMVER_EQ' | 'SEMVER_GT' | 'SEMVER_LT' | 'SEMVER_GTE' | 'SEMVER_LTE' | 'REGEX', required — The operator to use when evaluating this constraint. For more information about the various operators, refer to [the strategy constraint operator documentation](https://docs.getunleash.io/concepts/activation-strategies#constraint-operators).
    - `caseInsensitive` boolean — Whether the operator should be case sensitive or not. Defaults to `false` (being case sensitive).
    - `inverted` boolean — Whether the result should be negated or not. If `true`, will turn a `true` result into a `false` result and vice versa.
    - `values` string[] — The context values that should be used for constraint evaluation. Use this property instead of `value` for properties that accept multiple values.
    - `value` string — The context value that should be used for constraint evaluation. Use this property instead of `values` for properties that only accept single values.

## Response `201`

The resource was successfully created.

- AdminSegmentSchema — A description of a [segment](https://docs.getunleash.io/concepts/segments)
  - `id` integer, required — The ID of this segment
  - `name` string, required — The name of this segment
  - `description` string, nullable — The description for this segment
  - `constraints` ConstraintSchema[], required — The list of constraints that are used in this segment
    - `contextName` string, required — The name of the context field that this constraint should apply to.
    - `operator` 'NOT_IN' | 'IN' | 'STR_ENDS_WITH' | 'STR_STARTS_WITH' | 'STR_CONTAINS' | 'NUM_EQ' | 'NUM_GT' | 'NUM_GTE' | 'NUM_LT' | 'NUM_LTE' | 'DATE_AFTER' | 'DATE_BEFORE' | 'SEMVER_EQ' | 'SEMVER_GT' | 'SEMVER_LT' | 'SEMVER_GTE' | 'SEMVER_LTE' | 'REGEX', required — The operator to use when evaluating this constraint. For more information about the various operators, refer to [the strategy constraint operator documentation](https://docs.getunleash.io/concepts/activation-strategies#constraint-operators).
    - `caseInsensitive` boolean — Whether the operator should be case sensitive or not. Defaults to `false` (being case sensitive).
    - `inverted` boolean — Whether the result should be negated or not. If `true`, will turn a `true` result into a `false` result and vice versa.
    - `values` string[] — The context values that should be used for constraint evaluation. Use this property instead of `value` for properties that accept multiple values.
    - `value` string — The context value that should be used for constraint evaluation. Use this property instead of `values` for properties that only accept single values.
  - `usedInFeatures` integer, nullable — The number of feature flags that use this segment. The number also includes the any flags with pending change requests that would add this segment.
  - `usedInProjects` integer, nullable — The number of projects that use this segment. The number includes any projects with pending change requests that would add this segment.
  - `project` string, nullable — The project the segment belongs to. Only present if the segment is a project-specific segment.
  - `createdBy` string, nullable — The creator's email or username
  - `createdAt` string, date-time, required — When the segment was created

## Other responses

- `400` — The request data does not match what we expect.
- `401` — Authorization information is missing or invalid. Provide a valid API token as the `authorization` header, e.g. `authorization:*.*.my-admin-token`.
- `403` — The provided user credentials are valid, but the user does not have the necessary permissions to perform this operation
- `409` — The provided resource can not be created or updated because it would conflict with the current state of the resource or with an already existing resource, respectively.
- `415` — The operation does not support request payloads of the provided type. Please ensure that you're using one of the listed payload types and that you have specified the right content type in the "content-type" header.

---

[API](https://skmtc.net/unleash/apis/unleash-api-3.md) · [All operations](https://skmtc.net/unleash/apis/unleash-api-3/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/unleash/unleash-api-3/revisions/b2c3116e633e/schema)
