Big Segments is an Enterprise feature
This section documents endpoints for both standard segments and Big Segments. Big Segments is available to customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.
Segments allow you to create targeting rules and lists of individual targets that can be shared by one or more feature flags in an environment. Creating a segment is a lot like creating a flag. You can include individual targets in a segment. You can also create targeting rules, same as those for flags, that include or exclude targets based on attributes your application has provided about those targets. Finally, you can explicitly exclude targets that would otherwise be included by those rules. To learn more, read Segments.
The segments API allows you to list, create, modify, and delete segments programmatically.
For a given context instance with attributes, get membership details for all segments
Context instance segment membership collection response
Invalid request
Invalid access token
Invalid resource identifier
{- "key": "context-key-123abc",
- "kind": "user",
- "moreComplex": {
- "morethanone": [
- 1,
- 2,
- 3
], - "yes": "please"
}, - "name": "Some User",
- "something": true
}
{- "items": [
- {
- "name": "Segment Name",
- "key": "segment-key-123abc",
- "description": "Segment description",
- "unbounded": false,
- "isMember": true,
- "isIndividuallyTargeted": true,
- "isRuleTargeted": false,
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}
}
Get a list of all segments in the given project.
Segment collection response
Invalid access token
Invalid resource identifier
{- "items": [
- {
- "name": "Example segment",
- "description": "Bundle our sample customers together",
- "tags": [
- "testing"
], - "creationDate": 0,
- "lastModifiedDate": 0,
- "key": "segment-key-123abc",
- "included": [
- "user-key-123abc"
], - "excluded": [
- "user-key-123abc"
], - "includedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "excludedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "rules": [
- {
- "_id": "1234a56b7c89d012345e678f",
- "clauses": [
- {
- "_id": "12ab3c45de678910fab12345",
- "attribute": "email",
- "negate": false,
- "op": "endsWith",
- "values": [
- ".edu"
]
}
]
}
], - "version": 1,
- "deleted": false,
- "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- null
], - "actions": [
- "*"
], - "notActions": [
- null
], - "effect": "string",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- null
], - "actions": [
- "*"
], - "notActions": [
- null
], - "effect": "string",
- "role_name": "string"
}
}
]
}, - "_flags": [
- {
- "name": "string",
- "key": "string",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "unbounded": false,
- "unboundedContextKind": "string",
- "generation": 0,
- "_unboundedMetadata": {
- "envId": "string",
- "segmentId": "string",
- "version": 0,
- "includedCount": 0,
- "excludedCount": 0,
- "deleted": true
}, - "_external": "amplitude",
- "_importInProgress": false
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "totalCount": 0
}
Create a new segment.
Segment response
Invalid request
Invalid access token
Forbidden
Invalid resource identifier
Rate limited
{- "name": "Example segment",
- "key": "segment-key-123abc",
- "description": "Bundle our sample customers together",
- "tags": [
- "testing"
], - "unbounded": false,
- "unboundedContextKind": "device"
}
{- "name": "Example segment",
- "description": "Bundle our sample customers together",
- "tags": [
- "testing"
], - "creationDate": 0,
- "lastModifiedDate": 0,
- "key": "segment-key-123abc",
- "included": [
- "user-key-123abc"
], - "excluded": [
- "user-key-123abc"
], - "includedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "excludedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "rules": [
- {
- "_id": "1234a56b7c89d012345e678f",
- "clauses": [
- {
- "_id": "12ab3c45de678910fab12345",
- "attribute": "email",
- "negate": false,
- "op": "endsWith",
- "values": [
- ".edu"
]
}
]
}
], - "version": 1,
- "deleted": false,
- "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "string",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "string",
- "role_name": "string"
}
}
]
}, - "_flags": [
- {
- "name": "string",
- "key": "string",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "unbounded": false,
- "unboundedContextKind": "string",
- "generation": 0,
- "_unboundedMetadata": {
- "envId": "string",
- "segmentId": "string",
- "version": 0,
- "includedCount": 0,
- "excludedCount": 0,
- "deleted": true
}, - "_external": "amplitude",
- "_importInProgress": false
}
Get a single segment by key.
Segment response
Invalid access token
Invalid resource identifier
Rate limited
{- "name": "Example segment",
- "description": "Bundle our sample customers together",
- "tags": [
- "testing"
], - "creationDate": 0,
- "lastModifiedDate": 0,
- "key": "segment-key-123abc",
- "included": [
- "user-key-123abc"
], - "excluded": [
- "user-key-123abc"
], - "includedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "excludedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "rules": [
- {
- "_id": "1234a56b7c89d012345e678f",
- "clauses": [
- {
- "_id": "12ab3c45de678910fab12345",
- "attribute": "email",
- "negate": false,
- "op": "endsWith",
- "values": [
- ".edu"
]
}
]
}
], - "version": 1,
- "deleted": false,
- "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "string",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "string",
- "role_name": "string"
}
}
]
}, - "_flags": [
- {
- "name": "string",
- "key": "string",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "unbounded": false,
- "unboundedContextKind": "string",
- "generation": 0,
- "_unboundedMetadata": {
- "envId": "string",
- "segmentId": "string",
- "version": 0,
- "includedCount": 0,
- "excludedCount": 0,
- "deleted": true
}, - "_external": "amplitude",
- "_importInProgress": false
}
Update a segment. The request body must be a valid semantic patch, JSON patch, or JSON merge patch.
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.
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.Semantic patch requests support the following kind
instructions for updating segments.
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.
contextKind
: The context kind the targets should be added to.values
: List of keys.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. If you are working with contexts, use addIncludedTargets
instead of this instruction.
values
: List of user keys.Adds context keys to the individual context targets excluded in the segment for the specified contextKind
. Returns an error if this causes the same context key to be both included and excluded.
contextKind
: The context kind the targets should be added to.values
: List of keys.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. If you are working with contexts, use addExcludedTargets
instead of this instruction.
values
: List of user keys.Removes context keys from the individual context targets included in the segment for the specified contextKind
.
contextKind
: The context kind the targets should be removed from.values
: List of keys.Removes user keys from the individual user targets included in the segment. If you are working with contexts, use removeIncludedTargets
instead of this instruction.
values
: List of user keys.Removes context keys from the individual context targets excluded from the segment for the specified contextKind
.
contextKind
: The context kind the targets should be removed from.values
: List of keys.Removes user keys from the individual user targets excluded from the segment. If you are working with contexts, use removeExcludedTargets
instead of this instruction.
values
: List of user keys.Updates the name of the segment.
value
: Name of the segment.You can also use JSON patch. To learn more, read Updates using JSON patches.
For example, to update the description for a segment, use the following request body:
{
"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>
. Using /0
adds the new entry to the beginning of the array.
For example, to add a rule to a segment, use the following request body:
{
"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.
Segment response
Invalid request
Invalid access token
Forbidden
Invalid resource identifier
Status conflict
Rate limited
{- "patch": [
- {
- "op": "replace",
- "path": "/description",
- "value": "New description for this segment"
}, - {
- "op": "add",
- "path": "/tags/0",
- "value": "example"
}
]
}
{- "name": "Example segment",
- "description": "Bundle our sample customers together",
- "tags": [
- "testing"
], - "creationDate": 0,
- "lastModifiedDate": 0,
- "key": "segment-key-123abc",
- "included": [
- "user-key-123abc"
], - "excluded": [
- "user-key-123abc"
], - "includedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "excludedContexts": [
- {
- "values": [
- "string"
], - "contextKind": "string"
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "rules": [
- {
- "_id": "1234a56b7c89d012345e678f",
- "clauses": [
- {
- "_id": "12ab3c45de678910fab12345",
- "attribute": "email",
- "negate": false,
- "op": "endsWith",
- "values": [
- ".edu"
]
}
]
}
], - "version": 1,
- "deleted": false,
- "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "string",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "string",
- "role_name": "string"
}
}
]
}, - "_flags": [
- {
- "name": "string",
- "key": "string",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "unbounded": false,
- "unboundedContextKind": "string",
- "generation": 0,
- "_unboundedMetadata": {
- "envId": "string",
- "segmentId": "string",
- "version": 0,
- "includedCount": 0,
- "excludedCount": 0,
- "deleted": true
}, - "_external": "amplitude",
- "_importInProgress": false
}
Delete a segment.
Action succeeded
Invalid access token
Forbidden
Invalid resource identifier
Status conflict
Rate limited
{- "code": "unauthorized",
- "message": "Invalid access token"
}
Update context targets included or excluded in a Big Segment.
Action succeeded
Invalid request
Invalid access token
Invalid resource identifier
Rate limited
{- "included": {
- "add": [
- "string"
], - "remove": [
- "string"
]
}, - "excluded": {
- "add": [
- "string"
], - "remove": [
- "string"
]
}
}
{- "code": "invalid_request",
- "message": "Invalid request body"
}
Get the membership status (included/excluded) for a given context in this Big Segment. This operation does not support standard segments.
Segment membership for context response
Invalid request
Invalid access token
Invalid resource identifier
Rate limited
{- "userKey": "string",
- "included": true,
- "excluded": true
}
Update user context targets included or excluded in a Big Segment.
Action succeeded
Invalid request
Invalid access token
Invalid resource identifier
Rate limited
{- "included": {
- "add": [
- "string"
], - "remove": [
- "string"
]
}, - "excluded": {
- "add": [
- "string"
], - "remove": [
- "string"
]
}
}
{- "code": "invalid_request",
- "message": "Invalid request body"
}
Contexts are now available
After you have upgraded your LaunchDarkly SDK to use contexts instead of users, you should use Get expiring targets for segment instead of this endpoint. To learn more, read Contexts.
Get the membership status (included/excluded) for a given user in this Big Segment. This operation does not support standard segments.
Segment membership for user response
Invalid request
Invalid access token
Invalid resource identifier
Rate limited
{- "userKey": "string",
- "included": true,
- "excluded": true
}
Get a list of a segment's context targets that are scheduled for removal.
Expiring context target response
Invalid access token
Invalid resource identifier
Rate limited
{- "items": [
- {
- "_id": "12ab3c45de678910abc12345",
- "_version": 1,
- "expirationDate": 0,
- "contextKind": "user",
- "contextKey": "context-key-123abc",
- "targetType": "included",
- "variationId": "cc4332e2-bd4d-4fe0-b509-dfd2caf8dd73",
- "_resourceId": {
- "environmentKey": "environment-key-123abc",
- "flagKey": "string",
- "key": "segment-key-123abc",
- "kind": "string",
- "projectKey": "project-key-123abc"
}
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}
}
Update expiring context targets for a segment. Updating a context target expiration uses the semantic patch format.
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.
If the request is well-formed but any of its instructions failed to process, this operation returns status code 200
. In this case, the response errors
array will be non-empty.
Semantic patch requests support the following kind
instructions for updating context targets.
Schedules a date and time when LaunchDarkly will remove a context from segment targeting.
targetType
: A segment's target type, must be either included
or excluded
.contextKey
: The context key.contextKind
: The kind of context being targeted.value
: The date when the context should expire from the segment targeting, in Unix milliseconds.Updates the date and time when LaunchDarkly will remove a context from segment targeting.
targetType
: A segment's target type, must be either included
or excluded
.contextKey
: The context key.contextKind
: The kind of context being targeted.value
: The new date when the context should expire from the segment targeting, in Unix milliseconds.version
: The version of the expiring target to update. If included, update will fail if version doesn't match current version of the expiring target.Removes the scheduled expiration for the context in the segment.
targetType
: A segment's target type, must be either included
or excluded
.contextKey
: The context key.contextKind
: The kind of context being targeted.Expiring target response
Invalid request
Invalid access token
Forbidden
Invalid resource identifier
Status conflict
Rate limited
{- "comment": "optional comment",
- "instructions": [
- {
- "contextKey": "user@email.com",
- "contextKind": "user",
- "kind": "updateExpiringTarget",
- "targetType": "included",
- "value": 1587582000000,
- "version": 0
}
]
}
{- "items": [
- {
- "_id": "12ab3c45de678910abc12345",
- "_version": 1,
- "expirationDate": 0,
- "contextKind": "user",
- "contextKey": "context-key-123abc",
- "targetType": "included",
- "variationId": "cc4332e2-bd4d-4fe0-b509-dfd2caf8dd73",
- "_resourceId": {
- "environmentKey": "environment-key-123abc",
- "flagKey": "string",
- "key": "segment-key-123abc",
- "kind": "string",
- "projectKey": "project-key-123abc"
}
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "totalInstructions": 0,
- "successfulInstructions": 0,
- "failedInstructions": 0,
- "errors": [
- {
- "instructionIndex": 1,
- "message": "example error message"
}
]
}
Contexts are now available
After you have upgraded your LaunchDarkly SDK to use contexts instead of users, you should use Get expiring targets for segment instead of this endpoint. To learn more, read Contexts.
Get a list of a segment's user targets that are scheduled for removal.
Expiring user target response
Invalid access token
Invalid resource identifier
Rate limited
{- "items": [
- {
- "_id": "12ab3c45de678910fgh12345",
- "_version": 1,
- "expirationDate": 0,
- "userKey": "example-user-key",
- "targetType": "included",
- "variationId": "ce67d625-a8b9-4fb5-a344-ab909d9d4f4d",
- "_resourceId": {
- "kind": "string",
- "projectKey": "string",
- "environmentKey": "string",
- "flagKey": "string",
- "key": "string"
}
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}
}
Contexts are now available
After you have upgraded your LaunchDarkly SDK to use contexts instead of users, you should use Update expiring targets for segment instead of this endpoint. To learn more, read Contexts.
Update expiring user targets for a segment. Updating a user target expiration uses the semantic patch format.
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.
If the request is well-formed but any of its instructions failed to process, this operation returns status code 200
. In this case, the response errors
array will be non-empty.
Semantic patch requests support the following kind
instructions for updating user targets.
Schedules a date and time when LaunchDarkly will remove a user from segment targeting.
targetType
: A segment's target type, must be either included
or excluded
.userKey
: The user key.value
: The date when the user should expire from the segment targeting, in Unix milliseconds.Updates the date and time when LaunchDarkly will remove a user from segment targeting.
targetType
: A segment's target type, must be either included
or excluded
.userKey
: The user key.value
: The new date when the user should expire from the segment targeting, in Unix milliseconds.version
: The segment version.Removes the scheduled expiration for the user in the segment.
targetType
: A segment's target type, must be either included
or excluded
.userKey
: The user key.Expiring user target response
Invalid request
Invalid access token
Forbidden
Invalid resource identifier
Status conflict
Rate limited
{- "comment": "optional comment",
- "instructions": [
- {
- "contextKey": "contextKey",
- "contextKind": "user",
- "kind": "updateExpiringTarget",
- "targetType": "included",
- "value": 1587582000000,
- "version": 0
}
]
}
{- "items": [
- {
- "_id": "12ab3c45de678910fgh12345",
- "_version": 1,
- "expirationDate": 0,
- "userKey": "example-user-key",
- "targetType": "included",
- "variationId": "ce67d625-a8b9-4fb5-a344-ab909d9d4f4d",
- "_resourceId": {
- "kind": "string",
- "projectKey": "string",
- "environmentKey": "string",
- "flagKey": "string",
- "key": "string"
}
}
], - "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "totalInstructions": 1,
- "successfulInstructions": 1,
- "failedInstructions": 0,
- "errors": [
- {
- "instructionIndex": 1,
- "message": "example error message"
}
]
}