Update expiring targets for segment
For the complete documentation index, see llms.txt. For the full documentation snapshot, see llms-full.txt.
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.
Instructions
Semantic patch requests support the following kind instructions for updating expiring context targets.
Click to expand instructions for updating expiring context targets
addExpiringTarget
Schedules a date and time when LaunchDarkly will remove a context from segment targeting. The segment must already have the context as an individual target.
Parameters
targetType: The type of individual target for this context. Must be eitherincludedorexcluded.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.
Here’s an example:
{
"instructions": [{
"kind": "addExpiringTarget",
"targetType": "included",
"contextKey": "user-key-123abc",
"contextKind": "user",
"value": 1754092860000
}]
}
updateExpiringTarget
Updates the date and time when LaunchDarkly will remove a context from segment targeting.
Parameters
targetType: The type of individual target for this context. Must be eitherincludedorexcluded.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: (Optional) The version of the expiring target to update. If included, update will fail if version doesn’t match current version of the expiring target.
Here’s an example:
{
"instructions": [{
"kind": "updateExpiringTarget",
"targetType": "included",
"contextKey": "user-key-123abc",
"contextKind": "user",
"value": 1754179260000
}]
}
removeExpiringTarget
Removes the scheduled expiration for the context in the segment.
Parameters
targetType: The type of individual target for this context. Must be eitherincludedorexcluded.contextKey: The context key.contextKind: The kind of context being targeted.
Here’s an example:
{
"instructions": [{
"kind": "removeExpiringTarget",
"targetType": "included",
"contextKey": "user-key-123abc",
"contextKind": "user",
}]
}
curl --request PATCH \
--url https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"instructions": [
{
"contextKey": "user@email.com",
"contextKind": "user",
"kind": "updateExpiringTarget",
"targetType": "included",
"value": 1587582000000,
"version": 0
}
],
"comment": "optional comment"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}"
payload = {
"instructions": [
{
"contextKey": "user@email.com",
"contextKind": "user",
"kind": "updateExpiringTarget",
"targetType": "included",
"value": 1587582000000,
"version": 0
}
],
"comment": "optional comment"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
instructions: [
{
contextKey: 'user@email.com',
contextKind: 'user',
kind: 'updateExpiringTarget',
targetType: 'included',
value: 1587582000000,
version: 0
}
],
comment: 'optional comment'
})
};
fetch('https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'instructions' => [
[
'contextKey' => 'user@email.com',
'contextKind' => 'user',
'kind' => 'updateExpiringTarget',
'targetType' => 'included',
'value' => 1587582000000,
'version' => 0
]
],
'comment' => 'optional comment'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}"
payload := strings.NewReader("{\n \"instructions\": [\n {\n \"contextKey\": \"user@email.com\",\n \"contextKind\": \"user\",\n \"kind\": \"updateExpiringTarget\",\n \"targetType\": \"included\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"instructions\": [\n {\n \"contextKey\": \"user@email.com\",\n \"contextKind\": \"user\",\n \"kind\": \"updateExpiringTarget\",\n \"targetType\": \"included\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"instructions\": [\n {\n \"contextKey\": \"user@email.com\",\n \"contextKind\": \"user\",\n \"kind\": \"updateExpiringTarget\",\n \"targetType\": \"included\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"_id": "12ab3c45de678910abc12345",
"_version": 1,
"expirationDate": "1672358400000",
"contextKind": "user",
"contextKey": "context-key-123abc",
"_resourceId": {
"environmentKey": "environment-key-123abc",
"flagKey": "<string>",
"key": "segment-key-123abc",
"kind": "segment",
"projectKey": "project-key-123abc"
},
"targetType": "included",
"variationId": "cc4332e2-bd4d-4fe0-b509-dfd2caf8dd73"
}
],
"_links": {},
"totalInstructions": 123,
"successfulInstructions": 123,
"failedInstructions": 123,
"errors": [
{
"instructionIndex": 1,
"message": "example error message"
}
]
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "optimistic_locking_error",
"message": "Conflict. Optimistic lock error. Try again later."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Authorizations
Path Parameters
The project key
The environment key
The segment key
Body
Semantic patch instructions for the desired changes to the resource
Show child attributes
Show child attributes
[
{
"contextKey": "user@email.com",
"contextKind": "user",
"kind": "updateExpiringTarget",
"targetType": "included",
"value": 1587582000000,
"version": 0
}
]
Optional description of changes
"optional comment"
Response
Expiring target response
curl --request PATCH \
--url https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"instructions": [
{
"contextKey": "user@email.com",
"contextKind": "user",
"kind": "updateExpiringTarget",
"targetType": "included",
"value": 1587582000000,
"version": 0
}
],
"comment": "optional comment"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}"
payload = {
"instructions": [
{
"contextKey": "user@email.com",
"contextKind": "user",
"kind": "updateExpiringTarget",
"targetType": "included",
"value": 1587582000000,
"version": 0
}
],
"comment": "optional comment"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
instructions: [
{
contextKey: 'user@email.com',
contextKind: 'user',
kind: 'updateExpiringTarget',
targetType: 'included',
value: 1587582000000,
version: 0
}
],
comment: 'optional comment'
})
};
fetch('https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'instructions' => [
[
'contextKey' => 'user@email.com',
'contextKind' => 'user',
'kind' => 'updateExpiringTarget',
'targetType' => 'included',
'value' => 1587582000000,
'version' => 0
]
],
'comment' => 'optional comment'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}"
payload := strings.NewReader("{\n \"instructions\": [\n {\n \"contextKey\": \"user@email.com\",\n \"contextKind\": \"user\",\n \"kind\": \"updateExpiringTarget\",\n \"targetType\": \"included\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"instructions\": [\n {\n \"contextKey\": \"user@email.com\",\n \"contextKind\": \"user\",\n \"kind\": \"updateExpiringTarget\",\n \"targetType\": \"included\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"instructions\": [\n {\n \"contextKey\": \"user@email.com\",\n \"contextKind\": \"user\",\n \"kind\": \"updateExpiringTarget\",\n \"targetType\": \"included\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"_id": "12ab3c45de678910abc12345",
"_version": 1,
"expirationDate": "1672358400000",
"contextKind": "user",
"contextKey": "context-key-123abc",
"_resourceId": {
"environmentKey": "environment-key-123abc",
"flagKey": "<string>",
"key": "segment-key-123abc",
"kind": "segment",
"projectKey": "project-key-123abc"
},
"targetType": "included",
"variationId": "cc4332e2-bd4d-4fe0-b509-dfd2caf8dd73"
}
],
"_links": {},
"totalInstructions": 123,
"successfulInstructions": 123,
"failedInstructions": 123,
"errors": [
{
"instructionIndex": 1,
"message": "example error message"
}
]
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "optimistic_locking_error",
"message": "Conflict. Optimistic lock error. Try again later."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}