---
title: "Save a segment"
method: POST
path: "/segments"
tags: ["Campaigns"]
---

# Save a segment

`POST /segments`

## Request

- Base URL: `https://sendhq.cc/api/v1`
- URL: `https://sendhq.cc/api/v1/segments`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/sendhq/apis/sendhq-api/docs/segments/post.ts> (a function with typed inputs; its response is checked against the schema)

Save up to 20 `conditions` joined by `match` (`all`, the default, or `any`). Each condition is `{ field, op, value }`: `tag` (has, not_has), `list` (in, not_in a list ID), `status` (is, is_not, including `dormant`), `source` (is, is_not), `email` (contains, not_contains, ends_with), `name` (is_set, not_set), `signed_up` (before, after a date; in_last_days, not_in_last_days), `opened` and `clicked` (in_last_days, not_in_last_days, ever, never), `opens` and `sends_without_open` (gte, lte), `country` (is, is_not a two-letter code), and custom fields as `fields.<key>` or `{ field: "field", key }` (equals, not_equals, contains, gt, lt, before, after, is_set, not_set). Opened and clicked use estimated, bot-filtered engagement. A workspace may have 200 segments.

## Request body

- object
  - `name` string, required
  - `match` 'all' | 'any'
  - `conditions` object[]
    - `field` string, required: One of tag, list, status, source, email, name, signed_up, opened, clicked, opens, sends_without_open, country, or a custom field as `fields.<key>` (or `field` with `key`).
    - `key` string: Custom field key when `field` is `field`.
    - `op` string, required: Operator allowed for the field (see `fields` in GET /segments).
    - `value` union: Required except for is_set, not_set, ever, and never. Day counts and numbers for in_last_days, not_in_last_days, gte, lte, gt, and lt; YYYY-MM-DD for before and after.
      - string
      - number

## Response `201`

Successful response

- object
  - `id` string, required
  - `name` string, required
  - `match` string, required
  - `conditions` object[], required
    - `field` string, required
    - `op` string, required
    - `value` unknown, required
  - `count` integer, required
  - `createdAt` string, date-time, required
  - `updatedAt` string, date-time, required

## Other responses

- `400`: Invalid request
- `401`: Missing or invalid authentication
- `402`: A paid entitlement is required for this recipient or feature
- `403`: The workspace, domain, policy, or suppression state forbids the operation
- `404`: Tenant-scoped resource not found
- `409`: Resource state or idempotency conflict
- `413`: Attachment count or bytes exceed the accepted limit
- `422`: Request validation or suppression check failed
- `423`: Sending is paused for this sender identity or workspace; the message gives the reason and how to appeal
- `429`: A monthly, daily, or trial usage limit was reached
- `500`: Unexpected server error
- `502`: An upstream provider operation failed
- `503`: A required provider or signing configuration is unavailable
- `default`: An error response using SendHQ's standard JSON envelope

---

[API](https://skmtc.dev/sendhq/apis/sendhq-api.md) - [All operations](https://skmtc.dev/sendhq/apis/sendhq-api/llms.txt) - [OpenAPI document](https://skmtc.dev/sendhq/apis/sendhq-api/revisions/98e39e48cb9a?raw)
