Skip to main content
POST
/
api
/
v2
/
segments
/
{projectKey}
/
{environmentKey}
Create segment
curl --request POST \
  --url https://app.launchdarkly.com/api/v2/segments/{projectKey}/{environmentKey} \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "Example segment",
  "key": "segment-key-123abc",
  "description": "Bundle our sample customers together",
  "tags": [
    "testing"
  ],
  "unbounded": false,
  "unboundedContextKind": "device"
}
'
{
  "name": "Example segment",
  "tags": [
    "testing"
  ],
  "creationDate": "1654104600000",
  "lastModifiedDate": "1654104600000",
  "key": "segment-key-123abc",
  "_links": {},
  "rules": [
    {
      "_id": "1234a56b7c89d012345e678f",
      "clauses": [
        {
          "_id": "12ab3c45de678910fab12345",
          "attribute": "email",
          "negate": false,
          "op": "endsWith",
          "values": [
            ".edu"
          ]
        }
      ]
    }
  ],
  "version": 1,
  "deleted": false,
  "generation": 123,
  "description": "Bundle our sample customers together",
  "included": [
    "user-key-123abc"
  ],
  "excluded": [
    "user-key-123abc"
  ],
  "includedContexts": [
    {
      "values": [
        "<string>"
      ],
      "contextKind": "<string>"
    }
  ],
  "excludedContexts": [
    {
      "values": [
        "<string>"
      ],
      "contextKind": "<string>"
    }
  ],
  "_access": {
    "denied": [
      {
        "action": "<string>",
        "reason": {
          "effect": "allow",
          "resources": [
            "proj/*:env/*;qa_*:/flag/*"
          ],
          "notResources": [
            "<string>"
          ],
          "actions": [
            "*"
          ],
          "notActions": [
            "<string>"
          ],
          "role_name": "<string>"
        }
      }
    ],
    "allowed": [
      {
        "action": "<string>",
        "reason": {
          "effect": "allow",
          "resources": [
            "proj/*:env/*;qa_*:/flag/*"
          ],
          "notResources": [
            "<string>"
          ],
          "actions": [
            "*"
          ],
          "notActions": [
            "<string>"
          ],
          "role_name": "<string>"
        }
      }
    ]
  },
  "_flags": [
    {
      "name": "Example flag",
      "key": "flag-key-123abc",
      "_links": {},
      "_site": {
        "href": "<string>",
        "type": "<string>"
      }
    }
  ],
  "unbounded": false,
  "unboundedContextKind": "<string>",
  "_unboundedMetadata": {
    "envId": "<string>",
    "segmentId": "<string>",
    "version": 123,
    "includedCount": 123,
    "excludedCount": 123,
    "lastModified": 123,
    "deleted": true
  },
  "_external": "amplitude",
  "_externalLink": "https://analytics.amplitude.com/org/1234/cohort/123abc",
  "_importInProgress": false
}

Documentation Index

Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Authorizations

Authorization
string
header
required

Path Parameters

projectKey
string<string>
required

The project key

environmentKey
string<string>
required

The environment key

Body

application/json
name
string
required

A human-friendly name for the segment

Example:

"Example segment"

key
string
required

A unique key used to reference the segment

Example:

"segment-key-123abc"

description
string

A description of the segment's purpose

Example:

"Bundle our sample customers together"

tags
string[]

Tags for the segment

Example:
["testing"]
unbounded
boolean

Whether to create a standard segment (false) or a big segment (true). Standard segments include rule-based and smaller list-based segments. Big segments include larger list-based segments and synced segments. Only use a big segment if you need to add more than 15,000 individual targets.

Example:

false

unboundedContextKind
string

For big segments, the targeted context kind.

Example:

"device"

Response

Segment response

name
string
required

A human-friendly name for the segment.

Example:

"Example segment"

tags
string[]
required

Tags for the segment. Defaults to an empty array.

Example:
["testing"]
creationDate
integer<int64>
required

Timestamp of when the segment was created

Example:

"1654104600000"

lastModifiedDate
integer<int64>
required

Timestamp of when the segment was last modified

Example:

"1654104600000"

key
string
required

A unique key used to reference the segment

Example:

"segment-key-123abc"

The location and content type of related resources

rules
object[]
required

An array of the targeting rules for this segment.

Example:
[
{
"_id": "1234a56b7c89d012345e678f",
"clauses": [
{
"_id": "12ab3c45de678910fab12345",
"attribute": "email",
"negate": false,
"op": "endsWith",
"values": [".edu"]
}
]
}
]
version
integer
required

Version of the segment

Example:

1

deleted
boolean
required

Whether the segment has been deleted

Example:

false

generation
integer
required

For big segments, how many times this segment has been created.

description
string

A description of the segment's purpose. Defaults to null and is omitted in the response if not provided.

Example:

"Bundle our sample customers together"

included
string[]

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.

Example:
["user-key-123abc"]
excluded
string[]

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.

Example:
["user-key-123abc"]
includedContexts
object[]
excludedContexts
object[]
_access
object
_flags
object[]

A list of flags targeting this segment. Only included when getting a single segment, using the getSegment endpoint.

unbounded
boolean

Whether this is a standard segment (false) or a big segment (true). 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
string

For big segments, the targeted context kind.

_unboundedMetadata
object

Details on the external data store backing this segment. Only applies to big segments.

_external
string

The external data store backing this segment. Only applies to synced segments.

Example:

"amplitude"

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
boolean

Whether an import is currently in progress for the specified segment. Only applies to big segments.

Example:

false