---
title: "Edit a dynamic segment"
method: PATCH
path: "/assets/{asset_id}/dynamic-segments/{segment_id}"
tags: ["DynamicSegments"]
---

# Edit a dynamic segment

`PATCH /assets/{asset_id}/dynamic-segments/{segment_id}`

## Request

- Base URL: `https://enterprise.knak.io/api/published/v1`
- URL: `https://enterprise.knak.io/api/published/v1/assets/{asset_id}/dynamic-segments/{segment_id}`
- Auth: none declared
- TypeScript: <https://skmtc.dev/knak/apis/knak-enterprise-api/docs/assets/:asset_id/dynamic-segments/:segment_id/patch.ts> (a function with typed inputs; its response is checked against the schema)

Rename a [dynamic segment](#tag/dynamic_segment), replace its platform segments, or both.
Requires the `local_dynamic_segments` permission. Global segments cannot be edited through an asset route and return 422.

## Both properties are optional
Anything you leave out is left alone. A body of `{"name": "New name"}` renames the segment and does not touch its platform segments. An empty body changes nothing.

## Sending platform_dynamic_segments replaces the whole collection
**This is destructive.** When you send the property, the collection you send becomes the collection that exists:
- An entry **with** an `id` updates that platform segment in place
- An entry **without** an `id` creates a new platform segment
- An existing platform segment you **leave out is deleted**
- An **empty array deletes all of them**

Omitting the property entirely is the only way to leave the collection untouched. A client that reads a segment, drops a property it does not recognize, and writes the result back **will delete platform segments**. If you only mean to rename, send `name` on its own.

An `id` that belongs to a different segment is rejected with 422 and nothing is written.

## The segment id is stable
Content variants address a segment by its id, so replacing every platform segment does not break variants already pointing at it.

## Atomicity
Validation of every entry completes before any write, and the delete, update, and create steps run in one transaction. A request that fails partway leaves the segment exactly as it was.

Operators, value rules, and limits are identical to the create operation.

## Path parameters

- `asset_id` string, required
- `segment_id` string, required

## Request body

- object
  - `name` string: Must be unique among the other segments on this asset. Renaming a segment to its own current name is allowed.
  - `platform_dynamic_segments` PlatformDynamicSegmentUpdateInput[]: Replaces the entire collection. Omit to leave it untouched; send an empty array to remove every platform segment.
    - `id` string, nullable: Id of an existing platform segment on this dynamic segment. Omit to create a new one. An id belonging to a different segment is rejected with 422.
    - `platform` 'marketing_cloud', required: Only `marketing_cloud` is supported for segment conditional logic. Any other platform is rejected with 422.
    - `integration_id` string, nullable: Id of the [integration](#tag/integration) to bind this platform segment to. Optional. When supplied it must belong to `platform`.
    - `conditional_logic` DynamicSegmentConditionSetInput, required: A group of conditions in a request body, joined by `and` or `or`. Condition sets nest to a maximum depth of 4.
      - `type` 'condition_set', required
      - `conjunction` 'and' | 'or', required: How the entries in `children` combine.
      - `children` union[], required: Conditions and nested condition sets. A single set holds at most 20 conditions and at most 5 nested condition sets.
        - union
          - DynamicSegmentConditionInput: A single condition in a request body. Identifies the merge tag by id; Knak derives the platform expression for you and returns it as `category` on read.
            - `type` 'condition', required
            - `merge_tag_id` string, required: Id of the [merge tag](#tag/merge_tag) this condition tests. Obtain it from `GET /merge-tags`. The tag must belong to your company and to the same platform as the enclosing platform segment.
            - `merge_tag_type` 'string' | 'number' | 'date' | 'relative_date' | 'boolean', required: The value type of the merge tag, which determines the operators available to this condition.
            - `operator` string, required: Must be an operator valid for `merge_tag_type`. See the operator table on the create operation.
            - `value` union: The value to compare against. **Omit this property entirely** for the four operators that take no value: `hasContent` and `not-hasContent` on `string`, `isTrue` and `isFalse` on `boolean`. If you send `value` anyway for one of these four operators, it is ignored rather than rejected, regardless of its shape, including `null` or a string over 200 characters. Required for every other operator, where strings are limited to 200 characters.
              - …
          - DynamicSegmentConditionSetInput (recursive)

## Response `200`

OK. Returns the updated segment in the same shape as create.

- DynamicSegmentItem
  - `data` DynamicSegment
    - `type` string
    - `id` string
    - `attributes` DynamicSegmentAttributes
      - `id` string
      - `name` string: Unique among the segments on the same asset.
      - `asset_id` string, nullable: The asset this segment belongs to. Null for a global segment, which these endpoints can list but not create, edit, or delete.
      - `is_global` boolean: True when the segment is shared company wide rather than scoped to an asset.
      - `platform_dynamic_segments` PlatformDynamicSegment[]
        - `id` string
        - `platform` string: Not restricted to the platforms accepted on write. Segments authored in the builder for other platforms are returned here, and their `conditional_logic` will have a null `merge_tag_id` on its conditions.
        - `integration_id` string: Id of the [integration](#tag/integration) this platform segment is bound to. **An empty string when no integration is set**, never null.
        - `conditional_logic` DynamicSegmentConjunction: A group of conditions, joined by `and` or `or`.
          - `type` 'condition_set', required
          - `conjunction` 'and' | 'or': How the entries in `children` combine. Absent when the group has no conditions to combine.
          - `children` union[], required: Conditions and nested condition sets.
            - union
              - …

## Other responses

- `400`: Bad Request. The body is the wrong shape: a property has the wrong type, or `name` was sent as null or an empty string.
- `401`: Unauthenticated
- `403`: Unauthorized
- `404`: Not Found. The segment does not exist, does not belong to this asset, or the asset belongs to another company.
- `422`: Unprocessable Entity. The body is well formed but breaks a business rule.

---

[API](https://skmtc.dev/knak/apis/knak-enterprise-api.md) - [All operations](https://skmtc.dev/knak/apis/knak-enterprise-api/llms.txt) - [OpenAPI document](https://skmtc.dev/knak/apis/knak-enterprise-api/revisions/31d2c94edfcc?raw)
