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

# Create a segment

`POST /segments`

## Request

- Base URL: `https://www.unitpost.com/api/v1`
- URL: `https://www.unitpost.com/api/v1/segments`
- Auth: HTTP bearer

Create a segment — a named group of contacts you can target when sending a campaign. Once created, add contacts with [Add a member](#post-segments-id-contacts) and target it from [Create a campaign](#post-email-campaigns). A dynamic segment's `filter` is evaluated live: a condition on a custom field uses the field's `default_value` for any contact that has no value, and `is_set` / `is_not_set` check whether the contact itself has a value. To let recipients opt out of a category of mail instead, see [Create a topic](#post-email-topics). Requires the `segments:write` capability.

## Request body

- SegmentCreate
  - `name` string, required
  - `description` string
  - `type` 'static' | 'dynamic'
  - `filter` Schema0 (unresolved $ref)

## Response `201`

Created.

- Segment
  - `object` 'segment', required
  - `id` string, required
  - `name` string, required
  - `description` string, nullable, required
  - `type` 'static' | 'dynamic', required
  - `filter` Schema0, required (unresolved $ref)
  - `created_at` string, required
  - `updated_at` string, required

## Other responses

- `401`: Missing or invalid API key.
- `422`: Validation error.

---

[API](https://skmtc.dev/unitpost/apis/unitpost-api.md) · [All operations](https://skmtc.dev/unitpost/apis/unitpost-api/llms.txt) · [OpenAPI document](https://skmtc.dev/unitpost/apis/unitpost-api/revisions/86ff7c890967?raw)
