---
title: "Создать сегмент"
method: POST
path: "/v1/public/segments"
tags: ["Сегменты"]
---

# Создать сегмент

`POST /v1/public/segments`

## Request

- Base URL: `https://api.rusender.ru/api`
- URL: `https://api.rusender.ru/api/v1/public/segments`
- Auth: HTTP bearer

Создаёт пользовательский сегмент с произвольным набором условий.

## Headers

- `Idempotency-Key` string

## Request body

- object
  - `data` object, required: Основные данные запроса.
    - `name` string, required: Название сегмента.
    - `applyConditionsType` 'and' | 'or': Логика комбинирования условий. По умолчанию `and`.
    - `conditions` ConditionInputDto[]: Список условий сегмента (опционально).
      - `id` number: ID существующего условия. Передавайте при PATCH, чтобы обновить условие, а не создать новое.
      - `field` 'contactName' | 'contactEmail' | 'contactPhone' | 'contactStatus' | 'contactDateCreatedAt' | 'contactInList' | 'activeInCampaign' | 'variable', required: Поле, по которому фильтруем.
      - `variableId` number: ID переменной. Обязателен, если `field = variable`.
      - `operator` 'equal' | 'notEqual' | 'contain' | 'notContain' | 'thereIs' | 'missing' | 'participated' | 'notParticipated' | 'opened' | 'notOpened' | 'clicked' | 'notClicked' | 'before' | 'after' | 'findInList' | 'notFindInList', required: Оператор сравнения.
      - `value` string: Значение для сравнения. Не требуется для операторов `thereIs`/`missing`.
  - `meta` PublicApiRequestMetaDto
    - `requestId` string: Client-provided request ID для корреляции.

## Response `200`

Созданный сегмент.

- object
  - `ok` boolean, required: Флаг успешного выполнения.
  - `data` object, required: Полезная нагрузка успешного ответа.
    - `id` number, required: Идентификатор сегмента.
    - `name` string, required: Название сегмента.
    - `applyConditionsType` 'and' | 'or', required: Логика комбинирования условий: `and` — все, `or` — любое.
    - `conditions` ConditionDto[], required: Список условий сегмента.
      - `id` number, required: Идентификатор условия.
      - `field` 'contactName' | 'contactEmail' | 'contactPhone' | 'contactStatus' | 'contactDateCreatedAt' | 'contactInList' | 'activeInCampaign' | 'variable', required: Поле, по которому фильтруем (например, `contactEmail`).
      - `variableId` number: ID переменной (только если `field = variable`).
      - `operator` 'equal' | 'notEqual' | 'contain' | 'notContain' | 'thereIs' | 'missing' | 'participated' | 'notParticipated' | 'opened' | 'notOpened' | 'clicked' | 'notClicked' | 'before' | 'after' | 'findInList' | 'notFindInList', required: Оператор сравнения (`equal`, `contain`, `before` и т.д.).
      - `value` string: Значение для сравнения. Не требуется для операторов `thereIs`/`missing`.
    - `createdAt` string, required: Время создания (ISO 8601).
    - `updatedAt` string, required: Время обновления (ISO 8601).
    - `dashboardUrl` string, required: Ссылка на страницу сегментов в дашборде.
  - `meta` PublicApiResponseMetaDto, required
    - `requestId` string, required: Итоговый идентификатор запроса, использованный сервером.
    - `timestamp` string, required: Время формирования ответа в формате ISO-8601.
    - `pagination` PublicApiPaginationMetaDto
      - `page` number, required: Текущая страница.
      - `limit` number, required: Количество элементов на странице.
      - `totalItems` number, required: Общее количество элементов.
      - `totalPages` number, required: Общее количество страниц.

## Other responses

- `400`: Некорректный запрос.
- `401`: Требуется валидный токен Public API.
- `403`: Для вызова endpoint не хватает требуемого scope.
- `404`: Запрошенный ресурс не найден.
- `422`: Запрос синтаксически корректен, но не может быть обработан.
- `429`: Превышен rate limit для текущего API key.
- `500`: Внутренняя ошибка сервера.

---

[API](https://skmtc.dev/rusender/apis/public-api.md) · [All operations](https://skmtc.dev/rusender/apis/public-api/llms.txt) · [OpenAPI document](https://skmtc.dev/rusender/apis/public-api/revisions/8e86bca789ea?raw)
