# Edit a dynamic Segment

`PUT /v1/segments/{id}`

- Authentication: required (Bearer token)
- Required scope: `api.segments.manage`

Edits a Segment's name, description and predicate. On writes, `{id}`
resolves as a UUID or, failing that, as the Segment's org-unique key.
`key` is immutable (a `key` in the body is ignored).

Omitted fields keep their stored values, so a caller changing only
`source` does not have to resend the name to avoid blanking it.

Changing the predicate re-evaluates membership before the response
returns, exactly as create does — the `200` carries the new
`member_count` with `evaluation: "complete"`, or a `null` count with
`evaluation: "queued"`. An edit that leaves the definition byte-identical
skips the evaluation and returns no `evaluation` at all; the count on the
row is already the last real one.

Send `expected_content_hash` (the `content_hash` from a previous read) to
make the edit conditional. If the stored hash has moved on, the edit is
refused with `409 conflict` and the response body carries the row's
current `content_hash`, so a retry is one re-read away. Omit it and there
is no concurrency check.

Each successful edit snapshots the previous definition, so the change is
revertible.

## Path parameters

- `id` (string, required) — The Segment's UUID or, when the value does not parse as a UUID, its org-unique key. Unknown handles read as `404 not_found`. Accepted on every Segment route, read and write alike.

## Request body

Content type: `application/json`

```json
{
  "name": "string",
  "key": "string",
  "description": "string",
  "source": "string",
  "expected_content_hash": "string"
}
```

## Example request

```bash
curl -X PUT 'https://api.sendops.dev/v1/segments/string' \
  -H "Authorization: Bearer $SENDOPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"string","key":"string","description":"string","source":"string","expected_content_hash":"string"}'
```

## Responses

### 200 — The updated Segment, with its re-evaluated member count

Content type: `application/json`

```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "string",
  "key": "string",
  "description": "string",
  "source": "string",
  "profile_version": 0,
  "eval_class": "incremental",
  "status": "active",
  "member_count": 0,
  "evaluation": "complete",
  "eval_warning": "string",
  "eval_warning_at": "2026-05-17T20:00:00Z",
  "last_evaluated_at": "2026-05-17T20:00:00Z",
  "content_hash": "string",
  "warnings": [
    "string"
  ],
  "requires": [
    {
      "kind": "template",
      "key": "string",
      "status": "ok",
      "detail": "string",
      "fix": "string"
    }
  ],
  "created_at": "2026-05-17T20:00:00Z",
  "updated_at": "2026-05-17T20:00:00Z"
}
```

### 401 — Missing, malformed, or unknown API key

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 403 — Key lacks the required scope or plan limit violated

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 404 — Resource not found

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 409 — The write was refused by a state rule. Three cases, told apart by the extension members on the Problem: a stale `expected_content_hash` carries the row's current `content_hash`; and a delete blocked by a live dependent carries `referenced_by`.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ],
  "referenced_by": [
    {
      "kind": "workflow",
      "key": "string",
      "name": "string"
    }
  ]
}
```

### 422 — A query parameter, path value or body field failed validation.

The body is a `validation_failed` Problem. When the refusal is about a
reference — a segment key, template slug, topic or attribute name the
organization does not have — it additionally carries `validation_code`,
`field`, `line`/`column`, `missing`, `candidates` and `next_step`, so a
client can correct the call without a second round of guessing. See
`ValidationProblem`.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ],
  "validation_code": "invalid_syntax",
  "field": "string",
  "line": 0,
  "column": 0,
  "missing": [
    {
      "kind": "segment",
      "key": "string"
    }
  ],
  "candidates": {},
  "next_step": "string"
}
```

### 429 — Per-org rate limit exceeded

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 500 — Unexpected server-side failure. The `code` is `internal_error`. The
`request_id` field can be quoted to SendOps support to investigate.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```
