# Create segment (/api-reference/segments/createSegment)

`POST /segments`

Base URL: `https://next-api.useplunk.com`

Create a new audience segment.

**`DYNAMIC` segments** (the default) are defined by a `condition` — a boolean tree that is re-evaluated against your contacts, so membership changes on its own as contact data changes. `condition` is required for these.

**`STATIC` segments** hold a manually managed member list; `condition` is ignored. Add members with `POST /segments/{id}/members`.

## Request body

- `name`: string (required)
- `description`: string
- `type`: enum ("DYNAMIC" | "STATIC") — Defaults to `DYNAMIC` when omitted.
- `condition`: object — Required for `DYNAMIC` segments; ignored for `STATIC` ones.
- `trackMembership`: boolean — Emit `segment.<slug>.entry` / `segment.<slug>.exit` events as contacts join and leave. These can be used as workflow triggers.

Example:

```json
{
  "name": "string"
}
```

## Responses

### `201` — Segment created

- `id`: string
- `name`: string
- `description`: string
- `type`: enum ("DYNAMIC" | "STATIC") — `DYNAMIC` segments are evaluated from `condition`. `STATIC` segments hold a manually managed member list.
- `condition`: object — Filter condition for `DYNAMIC` segments. Null for `STATIC` segments.
- `trackMembership`: boolean — When true, contacts entering or leaving the segment emit `segment.<slug>.entry` / `segment.<slug>.exit` events.
- `memberCount`: integer — Cached member count, refreshed by a background job rather than computed per request.
- `projectId`: string
- `createdAt`: string (date-time)
- `updatedAt`: string (date-time)

```json
{
  "id": "string",
  "name": "string",
  "description": "string",
  "type": "DYNAMIC",
  "condition": {
    "logic": "AND",
    "groups": [
      {
        "filters": [
          {
            "field": "string",
            "operator": "equals"
          }
        ]
      }
    ]
  },
  "trackMembership": false,
  "memberCount": 0,
  "projectId": "string",
  "createdAt": "2026-08-09T17:56:20.166Z",
  "updatedAt": "2026-08-09T17:56:20.166Z"
}
```

### `400` — `name` is missing, or `condition` is missing on a `DYNAMIC` segment.

- `error`: string

```json
{
  "error": "string"
}
```

### `401` — Missing or invalid API key.

- `success`: enum (false)
- `error`: object
  - `code`: string — Machine-readable error code, e.g. `VALIDATION_ERROR`, `INVALID_API_KEY`, `IDEMPOTENCY_KEY_REUSED`.
  - `message`: string
  - `statusCode`: integer
  - `requestId`: string — Correlation ID for this request. Include it when contacting support.
  - `errors`: array<object> — Field-level detail, present on validation failures.
    items:
      - `field`: string — Dot-path of the offending field, e.g. `attachments.0.filename`.
      - `message`: string
      - `code`: string — Validation issue code, e.g. `invalid_type`, `too_big`, `reserved_event`.
      - `received`: object — The value that was received, when available.
  - `details`: object — Additional error context.
  - `suggestion`: string — Hint for fixing the request.
- `timestamp`: string (date-time)

```json
{
  "success": false,
  "error": {
    "code": "string",
    "message": "string",
    "statusCode": 0,
    "requestId": "string",
    "errors": [
      {
        "field": "string",
        "message": "string",
        "code": "string",
        "received": null
      }
    ],
    "details": null,
    "suggestion": "string"
  },
  "timestamp": "2026-08-09T17:56:20.166Z"
}
```

## Example request

```bash
curl -X POST 'https://next-api.useplunk.com/segments' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"name":"string"}'
```
