> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Patch segment

> > For the complete documentation index, see [llms.txt](https://launchdarkly-preview.mintlify.app/llms.txt). For the full documentation snapshot, see [llms-full.txt](https://launchdarkly-preview.mintlify.app/llms-full.txt).

Update a segment. The request body must be a valid semantic patch, JSON patch, or JSON merge patch. To learn more the different formats, read [Updates](https://launchdarkly.com/docs/api#updates).

### Using semantic patches on a segment

To make a semantic patch request, you must append `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header. To learn more, read [Updates using semantic patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch).

The body of a semantic patch request for updating segments requires an `environmentKey` in addition to `instructions` and an optional `comment`. The body of the request takes the following properties:

* `comment` (string): (Optional) A description of the update.
* `environmentKey` (string): (Required) The key of the LaunchDarkly environment.
* `instructions` (array): (Required) A list of actions the update should perform. Each action in the list must be an object with a `kind` property that indicates the instruction. If the action requires parameters, you must include those parameters as additional fields in the object.

### Instructions

Semantic patch requests support the following `kind` instructions for updating segments.

<details>
<summary>Click to expand instructions for <strong>updating segment details and settings</strong></summary>

#### addTags

Adds tags to the segment.

##### Parameters

- `values`: A list of tags to add.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addTags",
    "values": ["tag1", "tag2"]
  }]
}
```

#### removeTags

Removes tags from the segment.

##### Parameters

- `values`: A list of tags to remove.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeTags",
    "values": ["tag1", "tag2"]
  }]
}
```

#### updateName

Updates the name of the segment.

##### Parameters

- `value`: Name of the segment.

Here's an example:

```json
{
  "instructions": [{
    "kind": "updateName",
    "value": "Updated segment name"
  }]
}
```

</details>

<details>
<summary>Click to expand instructions for <strong>updating segment individual targets</strong></summary>

#### addExcludedTargets

Adds context keys to the individual context targets excluded from the segment for the specified `contextKind`. Returns an error if this causes the same context key to be both included and excluded, or if the number of operations on targets exceeds the batch limit of 1,500.

##### Parameters

- `contextKind`: The context kind the targets should be added to.
- `values`: List of keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addExcludedTargets",
    "contextKind": "org",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### addExcludedUsers

Adds user keys to the individual user targets excluded from the segment. Returns an error if this causes the same user key to be both included and excluded, or if the number of operations on targets exceeds the batch limit of 1,500. If you are working with contexts, use `addExcludedTargets` instead of this instruction.

##### Parameters

- `values`: List of user keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addExcludedUsers",
    "values": [ "user-key-123abc", "user-key-456def" ]
  }]
}
```

#### addIncludedTargets

Adds context keys to the individual context targets included in the segment for the specified `contextKind`. Returns an error if this causes the same context key to be both included and excluded, or if the number of operations on targets exceeds the batch limit of 1,500.

##### Parameters

- `contextKind`: The context kind the targets should be added to.
- `values`: List of keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addIncludedTargets",
    "contextKind": "org",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### addIncludedUsers

Adds user keys to the individual user targets included in the segment. Returns an error if this causes the same user key to be both included and excluded, or if the number of operations on targets exceeds the batch limit of 1,500. If you are working with contexts, use `addIncludedTargets` instead of this instruction.

##### Parameters

- `values`: List of user keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addIncludedUsers",
    "values": [ "user-key-123abc", "user-key-456def" ]
  }]
}
```

#### removeExcludedTargets

Removes context keys from the individual context targets excluded from the segment for the specified `contextKind`. Returns an error if the number of operations on targets exceeds the batch limit of 1,500.

##### Parameters

- `contextKind`: The context kind the targets should be removed from.
- `values`: List of keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeExcludedTargets",
    "contextKind": "org",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### removeExcludedUsers

Removes user keys from the individual user targets excluded from the segment. If you are working with contexts, use `removeExcludedTargets` instead of this instruction. Returns an error if the number of operations on targets exceeds the batch limit of 1,500.

##### Parameters

- `values`: List of user keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeExcludedUsers",
    "values": [ "user-key-123abc", "user-key-456def" ]
  }]
}
```

#### removeIncludedTargets

Removes context keys from the individual context targets included in the segment for the specified `contextKind`. Returns an error if the number of operations on targets exceeds the batch limit of 1,500.

##### Parameters

- `contextKind`: The context kind the targets should be removed from.
- `values`: List of keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeIncludedTargets",
    "contextKind": "org",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### removeIncludedUsers

Removes user keys from the individual user targets included in the segment. If you are working with contexts, use `removeIncludedTargets` instead of this instruction. Returns an error if the number of operations on targets exceeds the batch limit of 1,500.

##### Parameters

- `values`: List of user keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeIncludedUsers",
    "values": [ "user-key-123abc", "user-key-456def" ]
  }]
}
```

</details>

<details>
<summary>Click to expand instructions for <strong>updating segment targeting rules</strong></summary>

#### addClauses

Adds the given clauses to the rule indicated by `ruleId`.

##### Parameters

- `clauses`: Array of clause objects, with `contextKind` (string), `attribute` (string), `op` (string), `negate` (boolean), and `values` (array of strings, numbers, or dates) properties. The `contextKind`, if not provided, defaults to `user`. The `contextKind`, `attribute`, and `values` are case sensitive. The `op` must be lower-case.
- `ruleId`: ID of a rule in the segment.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addClauses",
    "clauses": [
      {
        "attribute": "email",
        "negate": false,
        "op": "contains",
        "values": ["value1"]
      }
    ],
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
  }]
}
```

#### addRule

Adds a new targeting rule to the segment. The rule may contain `clauses`.

##### Parameters

- `clauses`: Array of clause objects, with `contextKind` (string), `attribute` (string), `op` (string), `negate` (boolean), and `values` (array of strings, numbers, or dates) properties. The `contextKind`, if not provided, defaults to `user`. The `contextKind`, `attribute`, and `values` are case sensitive. The `op` must be lower-case.
- `description`: A description of the rule.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addRule",
    "clauses": [
      {
        "attribute": "email",
        "op": "contains",
        "negate": false,
        "values": ["@launchdarkly.com"]
      }
    ],
    "description": "Targeting rule for LaunchDarkly employees",
  }]
}
```

#### addValuesToClause

Adds `values` to the values of the clause that `ruleId` and `clauseId` indicate. Does not update the context kind, attribute, or operator.

##### Parameters

- `ruleId`: ID of a rule in the segment.
- `clauseId`: ID of a clause in that rule.
- `values`: Array of strings, case sensitive.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addValuesToClause",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
    "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
    "values": ["beta_testers"]
  }]
}
```

#### removeClauses

Removes the clauses specified by `clauseIds` from the rule indicated by `ruleId`.

##### Parameters

- `ruleId`: ID of a rule in the segment.
- `clauseIds`: Array of IDs of clauses in the rule.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeClauses",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
    "clauseIds": ["10a58772-3121-400f-846b-b8a04e8944ed", "36a461dc-235e-4b08-97b9-73ce9365873e"]
  }]
}
```

#### removeRule

Removes the targeting rule specified by `ruleId`. Does nothing if the rule does not exist.

##### Parameters

- `ruleId`: ID of a rule in the segment.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeRule",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
  }]
}
```

#### removeValuesFromClause

Removes `values` from the values of the clause indicated by `ruleId` and `clauseId`. Does not update the context kind, attribute, or operator.

##### Parameters

- `ruleId`: ID of a rule in the segment.
- `clauseId`: ID of a clause in that rule.
- `values`: Array of strings, case sensitive.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeValuesFromClause",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
    "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
    "values": ["beta_testers"]
  }]
}
```

#### reorderRules

Rearranges the rules to match the order given in `ruleIds`. Returns an error if `ruleIds` does not match the current set of rules in the segment.

##### Parameters

- `ruleIds`: Array of IDs of all targeting rules in the segment.

Here's an example:

```json
{
  "instructions": [{
    "kind": "reorderRules",
    "ruleIds": ["a902ef4a-2faf-4eaf-88e1-ecc356708a29", "63c238d1-835d-435e-8f21-c8d5e40b2a3d"]
  }]
}
```

#### updateClause

Replaces the clause indicated by `ruleId` and `clauseId` with `clause`.

##### Parameters

- `ruleId`: ID of a rule in the segment.
- `clauseId`: ID of a clause in that rule.
- `clause`: New `clause` object, with `contextKind` (string), `attribute` (string), `op` (string), `negate` (boolean), and `values` (array of strings, numbers, or dates) properties. The `contextKind`, if not provided, defaults to `user`. The `contextKind`, `attribute`, and `values` are case sensitive. The `op` must be lower-case.

Here's an example:

```json
{
  "instructions": [{
    "kind": "updateClause",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
    "clauseId": "10c7462a-2062-45ba-a8bb-dfb3de0f8af5",
    "clause": {
      "contextKind": "user",
      "attribute": "country",
      "op": "in",
      "negate": false,
      "values": ["Mexico", "Canada"]
    }
  }]
}
```

#### updateRuleDescription

Updates the description of the segment targeting rule.

##### Parameters

- `description`: The new human-readable description for this rule.
- `ruleId`: The ID of the rule. You can retrieve this by making a GET request for the segment.

Here's an example:

```json
{
  "instructions": [{
    "kind": "updateRuleDescription",
    "description": "New rule description",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
  }]
}
```

#### updateRuleRolloutAndContextKind

For a rule that includes a percentage of targets, updates the percentage and the context kind of the targets to include.

##### Parameters

- `ruleId`: The ID of a targeting rule in the segment that includes a percentage of targets.
- `weight`: The weight, in thousandths of a percent (0-100000).
- `contextKind`: The context kind.

Here's an example:

```json
{
  "instructions": [{
    "kind": "reorderRules",
    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
    "weight": "20000",
    "contextKind": "device"
  }]
}
```

</details>

<details>
<summary>Click to expand instructions for <strong>working with Big Segments</strong></summary>

A "big segment" is a segment that is either a synced segment, or a list-based segment with more than 15,000 entries that includes only one targeted context kind. LaunchDarkly uses different implementations for different types of segments so that all of your segments have good performance.

The following semantic patch instructions apply only to these [larger list-based segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments).

#### addBigSegmentExcludedTargets

For use with [larger list-based segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments) ONLY. Adds context keys to the context targets excluded from the segment. Returns an error if this causes the same context key to be both included and excluded.

##### Parameters

- `values`: List of context keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addBigSegmentExcludedTargets",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### addBigSegmentIncludedTargets

For use with [larger list-based segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments) ONLY. Adds context keys to the context targets included in the segment. Returns an error if this causes the same context key to be both included and excluded.

##### Parameters

- `values`: List of context keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addBigSegmentIncludedTargets",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### processBigSegmentImport

For use with [larger list-based segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments) ONLY. Processes a segment import.

##### Parameters

- `importId`: The ID of the import. The import ID is returned in the `Location` header as part of the [Create big segment import](https://launchdarkly.com/docs/api/segments/create-big-segment-import) request.

Here's an example:

```json
{
  "instructions": [{
    "kind": "processBigSegmentImport",
    "importId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
  }]
}
```


#### removeBigSegmentExcludedTargets

For use with [larger list-based segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments) ONLY. Removes context keys from the context targets excluded from the segment.

##### Parameters

- `values`: List of context keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeBigSegmentExcludedTargets",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

#### removeBigSegmentIncludedTargets

For use with [larger list-based segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments) ONLY. Removes context keys from the context targets included in the segment.

##### Parameters

- `values`: List of context keys.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeBigSegmentIncludedTargets",
    "values": [ "org-key-123abc", "org-key-456def" ]
  }]
}
```

</details>

### Using JSON patches on a segment

If you do not include the header described above, you can use a [JSON patch](https://launchdarkly.com/docs/api#updates-using-json-patch) or [JSON merge patch](https://datatracker.ietf.org/doc/html/rfc7386) representation of the desired changes.

For example, to update the description for a segment with a JSON patch, use the following request body:

```json
{
  "patch": [
    {
      "op": "replace",
      "path": "/description",
      "value": "new description"
    }
  ]
}
```

To update fields in the segment that are arrays, set the `path` to the name of the field and then append `/<array index>`. Use `/0` to add the new entry to the beginning of the array. Use `/-` to add the new entry to the end of the array.

For example, to add a rule to a segment, use the following request body:

```json
{
  "patch":[
    {
      "op": "add",
      "path": "/rules/0",
      "value": {
        "clauses": [{ "contextKind": "user", "attribute": "email", "op": "endsWith", "values": [".edu"], "negate": false }]
      }
    }
  ]
}
```

To add or remove targets from segments, we recommend using semantic patch. Semantic patch for segments includes specific instructions for adding and removing both included and excluded targets.




## OpenAPI

````yaml /openapi/launchdarkly-api.json patch /api/v2/segments/{projectKey}/{environmentKey}/{segmentKey}
openapi: 3.0.3
info:
  title: LaunchDarkly REST API
  description: >
    > For the complete documentation index, see
    https://launchdarkly-preview.mintlify.app/llms.txt.

    > For the full documentation snapshot, see
    https://launchdarkly-preview.mintlify.app/llms-full.txt.


    This is the LaunchDarkly REST API. It lets you build custom integrations,
    automate your workflow, and manage feature flags and other LaunchDarkly
    resources programmatically.


    For authentication, rate limits, pagination, versioning, JSON Patch and
    semantic patches, beta resources, and the full SDK End-of-Life table, read
    the [REST API overview](https://launchdarkly-preview.mintlify.app/api).


    To fetch the complete OpenAPI spec, use [Get OpenAPI
    spec](https://launchdarkly.com/docs/api/other/get-openapi-spec).
  contact:
    name: LaunchDarkly Technical Support Team
    url: https://support.launchdarkly.com
    email: support@launchdarkly.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: '2.0'
servers:
  - url: https://app.launchdarkly.com
    description: ' Default'
  - url: https://app.launchdarkly.us
    description: ' Federal'
security:
  - ApiKey:
      - read
      - write
tags:
  - name: Access tokens
    description: >-
      The access tokens API allows you to list, create, modify, and delete
      access tokens programmatically.
  - name: Account members
    description: >-
      The account members API allows you to invite new members to an account by
      making a `POST` request to `/api/v2/members`. When you invite a new member
      to an account, an invitation is sent to the email you provided.
  - name: Account usage (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: AI Configs
    description: >-
      The AI Configs API allows you to create, retrieve, and edit AI Configs, AI
      Config variations, and AI model configurations.
  - name: Announcements
    description: >-
      The announcements API lets you create and update a custom announcement
      banner that appears in the LaunchDarkly user interface for everyone in
      your organization.
  - name: Applications (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Approvals
    description: >-
      An account member can request approval on changes to a flag or AI Config's
      targeting or variations, or to a segment's targeting. Members may be
      required to request approval depending on the settings in their
      LaunchDarkly project.
  - name: Approvals (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Audit log
    description: >-
      LaunchDarkly maintains a record of all the changes made to any resource in
      the system. You can access this history using the audit log API, including
      filtering by timestamps, or using a custom policy to select which entries
      to receive.
  - name: Code references
    description: >-
      > ### Code references is an Enterprise feature > > Code references is
      available to customers on an Enterprise plan. To learn more, [read about
      our pricing](https://launchdarkly.com/pricing/).
  - name: Context settings
    description: >-
      You can use the context settings API to assign a context to a specific
      variation for any feature flag. To learn more, read [View and manage
      contexts](https://launchdarkly.com/docs/home/observability/context-attributes#view-and-manage-contexts).
  - name: Contexts
    description: >-
      Contexts are people, services, machines, or other resources that encounter
      feature flags in your product. Contexts are identified by their `kind`,
      which describes the type of resources encountering flags, and by their
      `key`.
  - name: Custom roles
    description: >-
      > ### Custom roles is an Enterprise feature > > Custom roles is available
      to customers on an Enterprise plan. To learn more, [read about our
      pricing](https://launchdarkly.com/pricing/).
  - name: Data Export destinations
    description: >-
      > ### Data Export is an add-on feature > > Data Export is available as an
      add-on for customers on a Foundation or Enterprise plan. To learn more,
      [read about our pricing](https://launchdarkly.com/pricing/).
  - name: Environments
    description: >-
      Environments allow you to maintain separate rollout rules in different
      contexts, from local development to QA, staging, and production. With the
      LaunchDarkly Environments API, you can programmatically list, create, and
      manage environments.
  - name: Experiments
    description: >-
      > ### Available for subscription customers > > Experimentation is
      available to all customers on a Developer, Foundation, or Enterprise
      subscription. If you're on an older Pro or Enterprise plan,
      Experimentation is available as an add-on.
  - name: Feature flags
    description: >-
      The feature flags API allows you to list, create, and modify feature flags
      and their targeting. For example, you can control percentage rollouts,
      target specific contexts, or even toggle off a feature flag
      programmatically.
  - name: Feature flags (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Flag import configurations (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Flag links (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Flag triggers
    description: >-
      > ### Flag triggers is an Enterprise feature > > Flag triggers is
      available to customers on an Enterprise plan. To learn more, [read about
      our pricing](https://launchdarkly.com/pricing/).
  - name: Follow flags
    description: >-
      Follow flags to receive email updates about targeting changes to a flag in
      a project and environment.
  - name: Holdouts (beta)
    description: >-
      > ### Available for customers using Experimentation > > Holdouts are
      available to customers using
      [Experimentation](https://launchdarkly.com/docs/api/experiments).
  - name: Insights charts (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Insights deployments (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Insights flag events (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Insights pull requests (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Insights repositories (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Insights scores (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Integration audit log subscriptions
    description: >-
      Audit log integration subscriptions allow you to send audit log events
      hooks to one of dozens of external tools. For example, you can send flag
      change event webhooks to external third party software.
  - name: Integration delivery configurations (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Integrations (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Layers
    description: >-
      > ### Available for customers using Experimentation > > Layers are
      available to customers using
      [Experimentation](https://launchdarkly.com/docs/api/experiments).
  - name: Metrics
    description: >-
      Metrics track flag behavior over time when an experiment is running. The
      data generated from experiments gives you more insight into the impact of
      a particular flag.
  - name: Metrics (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: OAuth2 Clients
    description: >-
      The OAuth2 client API allows you to register a LaunchDarkly OAuth client
      for use in your own custom integrations.
  - name: Persistent store integrations (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Projects
    description: >-
      Projects allow you to manage multiple different software projects under
      one LaunchDarkly account. Each project has its own unique set of
      environments and feature flags.
  - name: Relay Proxy configurations
    description: >-
      > ### Relay Proxy automatic configuration is an Enterprise feature > >
      Relay Proxy automatic configuration is available to customers on an
      Enterprise plan. To learn more, [read about our
      pricing](https://launchdarkly.com/pricing/).
  - name: Release pipelines (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Release policies (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Releases (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Scheduled changes
    description: >-
      > ### Scheduled flag changes is an Enterprise feature > > Scheduled flag
      changes is available to customers on an Enterprise plan. To learn more,
      [read about our pricing](https://launchdarkly.com/pricing/).
  - name: Segments
    description: >-
      > ### Synced segments and larger list-based segments are an Enterprise
      feature > > This section documents endpoints for rule-based, list-based,
      and synced segments.
  - name: Tags
    description: >-
      Tags are simple strings that you can attach to most resources in
      LaunchDarkly. Tags are useful for grouping resources into a set that you
      can name in a resource specifier.
  - name: Teams
    description: >-
      > ### Teams is an Enterprise feature > > Teams is available to customers
      on an Enterprise plan. To learn more, [read about our
      pricing](https://launchdarkly.com/pricing/).
  - name: Teams (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: User settings
    description: >-
      > ### Contexts are now available > > After you have upgraded your
      LaunchDarkly SDK to use contexts instead of users, you should use
      [Contexts](https://launchdarkly.com/docs/api/contexts) instead of the user
      settings API.
  - name: Users
    description: >-
      > ### Contexts are now available > > After you have upgraded your
      LaunchDarkly SDK to use contexts instead of users, you should use
      [Contexts](https://launchdarkly.com/docs/api/contexts) instead of these
      endpoints.
  - name: Users (beta)
    description: >-
      > ### Contexts are now available > > After you have upgraded your
      LaunchDarkly SDK to use contexts instead of users, you should use
      [Contexts](https://launchdarkly.com/docs/api/contexts) instead of these
      endpoints.
  - name: Views (beta)
    description: >-
      > ### This feature is in beta > > To use this feature, pass in a header
      including the `LD-API-Version` key with value set to `beta`. Use this
      header with each call.
  - name: Webhooks
    description: >-
      The webhooks API lets you build your own integrations that subscribe to
      activities in LaunchDarkly. When you generate an activity in LaunchDarkly,
      such as when you change a flag or you create a project, LaunchDarkly sends
      an HTTP POST payload to the...
  - name: Workflow templates
    description: >-
      > ### Workflows are in maintenance mode > > The workflows feature is in
      maintenance mode, and is planned for future deprecation at a date not yet
      specified.
  - name: Workflows
    description: >-
      > ### Workflows are in maintenance mode > > The workflows feature is in
      maintenance mode, and is planned for future deprecation at a date not yet
      specified.
  - name: Other
    description: Other requests available in the LaunchDarkly API.
paths:
  /api/v2/segments/{projectKey}/{environmentKey}/{segmentKey}:
    patch:
      tags:
        - Segments
      summary: Patch segment
      description: >
        > For the complete documentation index, see
        [llms.txt](https://launchdarkly-preview.mintlify.app/llms.txt). For the
        full documentation snapshot, see
        [llms-full.txt](https://launchdarkly-preview.mintlify.app/llms-full.txt).


        Update a segment. The request body must be a valid semantic patch, JSON
        patch, or JSON merge patch. To learn more the different formats, read
        [Updates](https://launchdarkly.com/docs/api#updates).


        ### Using semantic patches on a segment


        To make a semantic patch request, you must append
        `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header.
        To learn more, read [Updates using semantic
        patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch).


        The body of a semantic patch request for updating segments requires an
        `environmentKey` in addition to `instructions` and an optional
        `comment`. The body of the request takes the following properties:


        * `comment` (string): (Optional) A description of the update.

        * `environmentKey` (string): (Required) The key of the LaunchDarkly
        environment.

        * `instructions` (array): (Required) A list of actions the update should
        perform. Each action in the list must be an object with a `kind`
        property that indicates the instruction. If the action requires
        parameters, you must include those parameters as additional fields in
        the object.


        ### Instructions


        Semantic patch requests support the following `kind` instructions for
        updating segments.


        <details>

        <summary>Click to expand instructions for <strong>updating segment
        details and settings</strong></summary>


        #### addTags


        Adds tags to the segment.


        ##### Parameters


        - `values`: A list of tags to add.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addTags",
            "values": ["tag1", "tag2"]
          }]
        }

        ```


        #### removeTags


        Removes tags from the segment.


        ##### Parameters


        - `values`: A list of tags to remove.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeTags",
            "values": ["tag1", "tag2"]
          }]
        }

        ```


        #### updateName


        Updates the name of the segment.


        ##### Parameters


        - `value`: Name of the segment.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "updateName",
            "value": "Updated segment name"
          }]
        }

        ```


        </details>


        <details>

        <summary>Click to expand instructions for <strong>updating segment
        individual targets</strong></summary>


        #### addExcludedTargets


        Adds context keys to the individual context targets excluded from the
        segment for the specified `contextKind`. Returns an error if this causes
        the same context key to be both included and excluded, or if the number
        of operations on targets exceeds the batch limit of 1,500.


        ##### Parameters


        - `contextKind`: The context kind the targets should be added to.

        - `values`: List of keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addExcludedTargets",
            "contextKind": "org",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### addExcludedUsers


        Adds user keys to the individual user targets excluded from the segment.
        Returns an error if this causes the same user key to be both included
        and excluded, or if the number of operations on targets exceeds the
        batch limit of 1,500. If you are working with contexts, use
        `addExcludedTargets` instead of this instruction.


        ##### Parameters


        - `values`: List of user keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addExcludedUsers",
            "values": [ "user-key-123abc", "user-key-456def" ]
          }]
        }

        ```


        #### addIncludedTargets


        Adds context keys to the individual context targets included in the
        segment for the specified `contextKind`. Returns an error if this causes
        the same context key to be both included and excluded, or if the number
        of operations on targets exceeds the batch limit of 1,500.


        ##### Parameters


        - `contextKind`: The context kind the targets should be added to.

        - `values`: List of keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addIncludedTargets",
            "contextKind": "org",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### addIncludedUsers


        Adds user keys to the individual user targets included in the segment.
        Returns an error if this causes the same user key to be both included
        and excluded, or if the number of operations on targets exceeds the
        batch limit of 1,500. If you are working with contexts, use
        `addIncludedTargets` instead of this instruction.


        ##### Parameters


        - `values`: List of user keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addIncludedUsers",
            "values": [ "user-key-123abc", "user-key-456def" ]
          }]
        }

        ```


        #### removeExcludedTargets


        Removes context keys from the individual context targets excluded from
        the segment for the specified `contextKind`. Returns an error if the
        number of operations on targets exceeds the batch limit of 1,500.


        ##### Parameters


        - `contextKind`: The context kind the targets should be removed from.

        - `values`: List of keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeExcludedTargets",
            "contextKind": "org",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### removeExcludedUsers


        Removes user keys from the individual user targets excluded from the
        segment. If you are working with contexts, use `removeExcludedTargets`
        instead of this instruction. Returns an error if the number of
        operations on targets exceeds the batch limit of 1,500.


        ##### Parameters


        - `values`: List of user keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeExcludedUsers",
            "values": [ "user-key-123abc", "user-key-456def" ]
          }]
        }

        ```


        #### removeIncludedTargets


        Removes context keys from the individual context targets included in the
        segment for the specified `contextKind`. Returns an error if the number
        of operations on targets exceeds the batch limit of 1,500.


        ##### Parameters


        - `contextKind`: The context kind the targets should be removed from.

        - `values`: List of keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeIncludedTargets",
            "contextKind": "org",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### removeIncludedUsers


        Removes user keys from the individual user targets included in the
        segment. If you are working with contexts, use `removeIncludedTargets`
        instead of this instruction. Returns an error if the number of
        operations on targets exceeds the batch limit of 1,500.


        ##### Parameters


        - `values`: List of user keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeIncludedUsers",
            "values": [ "user-key-123abc", "user-key-456def" ]
          }]
        }

        ```


        </details>


        <details>

        <summary>Click to expand instructions for <strong>updating segment
        targeting rules</strong></summary>


        #### addClauses


        Adds the given clauses to the rule indicated by `ruleId`.


        ##### Parameters


        - `clauses`: Array of clause objects, with `contextKind` (string),
        `attribute` (string), `op` (string), `negate` (boolean), and `values`
        (array of strings, numbers, or dates) properties. The `contextKind`, if
        not provided, defaults to `user`. The `contextKind`, `attribute`, and
        `values` are case sensitive. The `op` must be lower-case.

        - `ruleId`: ID of a rule in the segment.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addClauses",
            "clauses": [
              {
                "attribute": "email",
                "negate": false,
                "op": "contains",
                "values": ["value1"]
              }
            ],
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
          }]
        }

        ```


        #### addRule


        Adds a new targeting rule to the segment. The rule may contain
        `clauses`.


        ##### Parameters


        - `clauses`: Array of clause objects, with `contextKind` (string),
        `attribute` (string), `op` (string), `negate` (boolean), and `values`
        (array of strings, numbers, or dates) properties. The `contextKind`, if
        not provided, defaults to `user`. The `contextKind`, `attribute`, and
        `values` are case sensitive. The `op` must be lower-case.

        - `description`: A description of the rule.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addRule",
            "clauses": [
              {
                "attribute": "email",
                "op": "contains",
                "negate": false,
                "values": ["@launchdarkly.com"]
              }
            ],
            "description": "Targeting rule for LaunchDarkly employees",
          }]
        }

        ```


        #### addValuesToClause


        Adds `values` to the values of the clause that `ruleId` and `clauseId`
        indicate. Does not update the context kind, attribute, or operator.


        ##### Parameters


        - `ruleId`: ID of a rule in the segment.

        - `clauseId`: ID of a clause in that rule.

        - `values`: Array of strings, case sensitive.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addValuesToClause",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
            "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
            "values": ["beta_testers"]
          }]
        }

        ```


        #### removeClauses


        Removes the clauses specified by `clauseIds` from the rule indicated by
        `ruleId`.


        ##### Parameters


        - `ruleId`: ID of a rule in the segment.

        - `clauseIds`: Array of IDs of clauses in the rule.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeClauses",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
            "clauseIds": ["10a58772-3121-400f-846b-b8a04e8944ed", "36a461dc-235e-4b08-97b9-73ce9365873e"]
          }]
        }

        ```


        #### removeRule


        Removes the targeting rule specified by `ruleId`. Does nothing if the
        rule does not exist.


        ##### Parameters


        - `ruleId`: ID of a rule in the segment.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeRule",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
          }]
        }

        ```


        #### removeValuesFromClause


        Removes `values` from the values of the clause indicated by `ruleId` and
        `clauseId`. Does not update the context kind, attribute, or operator.


        ##### Parameters


        - `ruleId`: ID of a rule in the segment.

        - `clauseId`: ID of a clause in that rule.

        - `values`: Array of strings, case sensitive.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeValuesFromClause",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
            "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
            "values": ["beta_testers"]
          }]
        }

        ```


        #### reorderRules


        Rearranges the rules to match the order given in `ruleIds`. Returns an
        error if `ruleIds` does not match the current set of rules in the
        segment.


        ##### Parameters


        - `ruleIds`: Array of IDs of all targeting rules in the segment.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "reorderRules",
            "ruleIds": ["a902ef4a-2faf-4eaf-88e1-ecc356708a29", "63c238d1-835d-435e-8f21-c8d5e40b2a3d"]
          }]
        }

        ```


        #### updateClause


        Replaces the clause indicated by `ruleId` and `clauseId` with `clause`.


        ##### Parameters


        - `ruleId`: ID of a rule in the segment.

        - `clauseId`: ID of a clause in that rule.

        - `clause`: New `clause` object, with `contextKind` (string),
        `attribute` (string), `op` (string), `negate` (boolean), and `values`
        (array of strings, numbers, or dates) properties. The `contextKind`, if
        not provided, defaults to `user`. The `contextKind`, `attribute`, and
        `values` are case sensitive. The `op` must be lower-case.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "updateClause",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
            "clauseId": "10c7462a-2062-45ba-a8bb-dfb3de0f8af5",
            "clause": {
              "contextKind": "user",
              "attribute": "country",
              "op": "in",
              "negate": false,
              "values": ["Mexico", "Canada"]
            }
          }]
        }

        ```


        #### updateRuleDescription


        Updates the description of the segment targeting rule.


        ##### Parameters


        - `description`: The new human-readable description for this rule.

        - `ruleId`: The ID of the rule. You can retrieve this by making a GET
        request for the segment.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "updateRuleDescription",
            "description": "New rule description",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
          }]
        }

        ```


        #### updateRuleRolloutAndContextKind


        For a rule that includes a percentage of targets, updates the percentage
        and the context kind of the targets to include.


        ##### Parameters


        - `ruleId`: The ID of a targeting rule in the segment that includes a
        percentage of targets.

        - `weight`: The weight, in thousandths of a percent (0-100000).

        - `contextKind`: The context kind.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "reorderRules",
            "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
            "weight": "20000",
            "contextKind": "device"
          }]
        }

        ```


        </details>


        <details>

        <summary>Click to expand instructions for <strong>working with Big
        Segments</strong></summary>


        A "big segment" is a segment that is either a synced segment, or a
        list-based segment with more than 15,000 entries that includes only one
        targeted context kind. LaunchDarkly uses different implementations for
        different types of segments so that all of your segments have good
        performance.


        The following semantic patch instructions apply only to these [larger
        list-based
        segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments).


        #### addBigSegmentExcludedTargets


        For use with [larger list-based
        segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments)
        ONLY. Adds context keys to the context targets excluded from the
        segment. Returns an error if this causes the same context key to be both
        included and excluded.


        ##### Parameters


        - `values`: List of context keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addBigSegmentExcludedTargets",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### addBigSegmentIncludedTargets


        For use with [larger list-based
        segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments)
        ONLY. Adds context keys to the context targets included in the segment.
        Returns an error if this causes the same context key to be both included
        and excluded.


        ##### Parameters


        - `values`: List of context keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addBigSegmentIncludedTargets",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### processBigSegmentImport


        For use with [larger list-based
        segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments)
        ONLY. Processes a segment import.


        ##### Parameters


        - `importId`: The ID of the import. The import ID is returned in the
        `Location` header as part of the [Create big segment
        import](https://launchdarkly.com/docs/api/segments/create-big-segment-import)
        request.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "processBigSegmentImport",
            "importId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
          }]
        }

        ```



        #### removeBigSegmentExcludedTargets


        For use with [larger list-based
        segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments)
        ONLY. Removes context keys from the context targets excluded from the
        segment.


        ##### Parameters


        - `values`: List of context keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeBigSegmentExcludedTargets",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        #### removeBigSegmentIncludedTargets


        For use with [larger list-based
        segments](https://launchdarkly.com/docs/home/flags/segments-create#create-larger-list-based-segments)
        ONLY. Removes context keys from the context targets included in the
        segment.


        ##### Parameters


        - `values`: List of context keys.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "removeBigSegmentIncludedTargets",
            "values": [ "org-key-123abc", "org-key-456def" ]
          }]
        }

        ```


        </details>


        ### Using JSON patches on a segment


        If you do not include the header described above, you can use a [JSON
        patch](https://launchdarkly.com/docs/api#updates-using-json-patch) or
        [JSON merge patch](https://datatracker.ietf.org/doc/html/rfc7386)
        representation of the desired changes.


        For example, to update the description for a segment with a JSON patch,
        use the following request body:


        ```json

        {
          "patch": [
            {
              "op": "replace",
              "path": "/description",
              "value": "new description"
            }
          ]
        }

        ```


        To update fields in the segment that are arrays, set the `path` to the
        name of the field and then append `/<array index>`. Use `/0` to add the
        new entry to the beginning of the array. Use `/-` to add the new entry
        to the end of the array.


        For example, to add a rule to a segment, use the following request body:


        ```json

        {
          "patch":[
            {
              "op": "add",
              "path": "/rules/0",
              "value": {
                "clauses": [{ "contextKind": "user", "attribute": "email", "op": "endsWith", "values": [".edu"], "negate": false }]
              }
            }
          ]
        }

        ```


        To add or remove targets from segments, we recommend using semantic
        patch. Semantic patch for segments includes specific instructions for
        adding and removing both included and excluded targets.
      operationId: patchSegment
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
            description: The project key
        - name: environmentKey
          in: path
          description: The environment key
          required: true
          schema:
            type: string
            format: string
            description: The environment key
        - name: segmentKey
          in: path
          description: The segment key
          required: true
          schema:
            type: string
            format: string
            description: The segment key
        - name: dryRun
          in: query
          description: >-
            If true, the patch will be validated but not persisted. Returns a
            preview of the segment after the patch is applied.
          schema:
            type: boolean
            description: >-
              If true, the patch will be validated but not persisted. Returns a
              preview of the segment after the patch is applied.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchWithComment'
            example:
              patch:
                - op: replace
                  path: /description
                  value: New description for this segment
                - op: add
                  path: /tags/0
                  value: example
        required: true
      responses:
        '200':
          description: Segment response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserSegment'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorRep'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenErrorRep'
        '404':
          description: Invalid resource identifier
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
        '409':
          description: Status conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusConflictErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
components:
  schemas:
    PatchWithComment:
      type: object
      required:
        - patch
      properties:
        patch:
          $ref: '#/components/schemas/JSONPatch'
          description: A JSON patch representation of the change to make
        comment:
          type: string
          description: Optional comment
    UserSegment:
      type: object
      required:
        - name
        - tags
        - creationDate
        - lastModifiedDate
        - key
        - _links
        - rules
        - version
        - deleted
        - generation
      properties:
        name:
          type: string
          description: A human-friendly name for the segment.
          example: Example segment
        description:
          type: string
          description: >-
            A description of the segment's purpose. Defaults to
            <code>null</code> and is omitted in the response if not provided.
          example: Bundle our sample customers together
        tags:
          type: array
          description: Tags for the segment. Defaults to an empty array.
          items:
            type: string
          example:
            - testing
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the segment was created
          example: '1654104600000'
        lastModifiedDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the segment was last modified
          example: '1654104600000'
        key:
          type: string
          description: A unique key used to reference the segment
          example: segment-key-123abc
        included:
          type: array
          description: >-
            An array of keys for included targets. Included individual targets
            are always segment members, regardless of segment rules. For
            list-based segments over 15,000 entries, also called big segments,
            this array is either empty or omitted.
          items:
            type: string
          example:
            - user-key-123abc
        excluded:
          type: array
          description: >-
            An array of keys for excluded targets. Segment rules bypass
            individual excluded targets, so they will never be included based on
            rules. Excluded targets may still be included explicitly. This value
            is omitted for list-based segments over 15,000 entries, also called
            big segments.
          items:
            type: string
          example:
            - user-key-123abc
        includedContexts:
          type: array
          items:
            $ref: '#/components/schemas/SegmentTarget'
        excludedContexts:
          type: array
          items:
            $ref: '#/components/schemas/SegmentTarget'
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        rules:
          type: array
          description: An array of the targeting rules for this segment.
          items:
            $ref: '#/components/schemas/UserSegmentRule'
          example:
            - _id: 1234a56b7c89d012345e678f
              clauses:
                - _id: 12ab3c45de678910fab12345
                  attribute: email
                  negate: false
                  op: endsWith
                  values:
                    - .edu
        version:
          type: integer
          description: Version of the segment
          example: 1
        deleted:
          type: boolean
          description: Whether the segment has been deleted
          example: false
        _access:
          $ref: '#/components/schemas/Access'
        _flags:
          type: array
          description: >-
            A list of flags targeting this segment. Only included when getting a
            single segment, using the <code>getSegment</code> endpoint.
          items:
            $ref: '#/components/schemas/FlagListingRep'
        unbounded:
          type: boolean
          description: >-
            Whether this is a standard segment (<code>false</code>) or a big
            segment (<code>true</code>). Standard segments include rule-based
            segments and smaller list-based segments. Big segments include
            larger list-based segments and synced segments. If omitted, the
            segment is a standard segment.
          example: false
        unboundedContextKind:
          type: string
          description: For big segments, the targeted context kind.
        generation:
          type: integer
          description: For big segments, how many times this segment has been created.
        _unboundedMetadata:
          $ref: '#/components/schemas/SegmentMetadata'
          description: >-
            Details on the external data store backing this segment. Only
            applies to big segments.
        _external:
          type: string
          description: >-
            The external data store backing this segment. Only applies to synced
            segments.
          example: amplitude
        _externalLink:
          type: string
          description: >-
            The URL for the external data store backing this segment. Only
            applies to synced segments.
          example: https://analytics.amplitude.com/org/1234/cohort/123abc
        _importInProgress:
          type: boolean
          description: >-
            Whether an import is currently in progress for the specified
            segment. Only applies to big segments.
          example: false
    InvalidRequestErrorRep:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Specific error code encountered
          example: invalid_request
        message:
          type: string
          description: Description of the error
          example: Invalid request body
    UnauthorizedErrorRep:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Specific error code encountered
          example: unauthorized
        message:
          type: string
          description: Description of the error
          example: Invalid access token
    ForbiddenErrorRep:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Specific error code encountered
          example: forbidden
        message:
          type: string
          description: Description of the error
          example: Forbidden. Access to the requested resource was denied.
    NotFoundErrorRep:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Specific error code encountered
          example: not_found
        message:
          type: string
          description: Description of the error
          example: Invalid resource identifier
    StatusConflictErrorRep:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Specific error code encountered
          example: optimistic_locking_error
        message:
          type: string
          description: Description of the error
          example: Conflict. Optimistic lock error. Try again later.
    RateLimitedErrorRep:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Specific error code encountered
          example: rate_limited
        message:
          type: string
          description: Description of the error
          example: You've exceeded the API rate limit. Try again later.
    JSONPatch:
      type: array
      items:
        $ref: '#/components/schemas/PatchOperation'
    UnixMillis:
      type: integer
      format: int64
    SegmentTarget:
      type: object
      properties:
        values:
          type: array
          items:
            type: string
        contextKind:
          type: string
    Link:
      type: object
      properties:
        href:
          type: string
        type:
          type: string
    UserSegmentRule:
      type: object
      required:
        - clauses
      properties:
        _id:
          type: string
        clauses:
          type: array
          items:
            $ref: '#/components/schemas/Clause'
        weight:
          type: integer
        rolloutContextKind:
          type: string
        bucketBy:
          type: string
        description:
          type: string
    Access:
      type: object
      required:
        - denied
        - allowed
      properties:
        denied:
          type: array
          items:
            $ref: '#/components/schemas/AccessDenied'
        allowed:
          type: array
          items:
            $ref: '#/components/schemas/AccessAllowedRep'
    FlagListingRep:
      type: object
      required:
        - name
        - key
      properties:
        name:
          type: string
          description: The flag name
          example: Example flag
        key:
          type: string
          description: The flag key
          example: flag-key-123abc
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        _site:
          $ref: '#/components/schemas/Link'
    SegmentMetadata:
      type: object
      properties:
        envId:
          type: string
        segmentId:
          $ref: '#/components/schemas/SegmentId'
        version:
          type: integer
        includedCount:
          type: integer
        excludedCount:
          type: integer
        lastModified:
          $ref: '#/components/schemas/UnixMillis'
        deleted:
          type: boolean
    PatchOperation:
      type: object
      required:
        - op
        - path
      properties:
        op:
          type: string
          description: The type of operation to perform
          example: replace
        path:
          type: string
          description: >-
            A JSON Pointer string specifying the part of the document to operate
            on
          example: /exampleField
        value:
          description: A JSON value used in "add", "replace", and "test" operations
          example: new example value
    Clause:
      type: object
      required:
        - attribute
        - op
        - values
        - negate
      properties:
        _id:
          type: string
        attribute:
          type: string
        op:
          $ref: '#/components/schemas/Operator'
        values:
          type: array
          items: {}
        contextKind:
          type: string
        negate:
          type: boolean
    AccessDenied:
      type: object
      required:
        - action
        - reason
      properties:
        action:
          $ref: '#/components/schemas/ActionIdentifier'
        reason:
          $ref: '#/components/schemas/AccessDeniedReason'
    AccessAllowedRep:
      type: object
      required:
        - action
        - reason
      properties:
        action:
          $ref: '#/components/schemas/ActionIdentifier'
        reason:
          $ref: '#/components/schemas/AccessAllowedReason'
    SegmentId:
      type: string
    Operator:
      type: string
    ActionIdentifier:
      type: string
    AccessDeniedReason:
      type: object
      required:
        - effect
      properties:
        resources:
          type: array
          description: Resource specifier strings
          items:
            type: string
          example:
            - proj/*:env/*;qa_*:/flag/*
        notResources:
          type: array
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
          items:
            type: string
        actions:
          type: array
          description: Actions to perform on a resource
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          example:
            - '*'
        notActions:
          type: array
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
          items:
            $ref: '#/components/schemas/ActionSpecifier'
        effect:
          type: string
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
          example: allow
          enum:
            - allow
            - deny
        role_name:
          type: string
    AccessAllowedReason:
      type: object
      required:
        - effect
      properties:
        resources:
          type: array
          description: Resource specifier strings
          items:
            type: string
          example:
            - proj/*:env/*;qa_*:/flag/*
        notResources:
          type: array
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
          items:
            type: string
        actions:
          type: array
          description: Actions to perform on a resource
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          example:
            - '*'
        notActions:
          type: array
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
          items:
            $ref: '#/components/schemas/ActionSpecifier'
        effect:
          type: string
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
          example: allow
          enum:
            - allow
            - deny
        role_name:
          type: string
    ActionSpecifier:
      type: string
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

````