Update expiring user targets for segment
For the complete documentation index, see llms.txt. For the full documentation snapshot, see llms-full.txt.
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.
Instructions
Semantic patch requests support the following kind instructions for updating expiring user targets.
Click to expand instructions for updating expiring user targets
addExpireUserTargetDate
Schedules a date and time when LaunchDarkly will remove a user from segment targeting.
Parameters
targetType: A segment’s target type, must be eitherincludedorexcluded.userKey: The user key.value: The date when the user should expire from the segment targeting, in Unix milliseconds.
updateExpireUserTargetDate
Updates the date and time when LaunchDarkly will remove a user from segment targeting.
Parameters
targetType: A segment’s target type, must be eitherincludedorexcluded.userKey: The user key.value: The new date when the user should expire from the segment targeting, in Unix milliseconds.version: The segment version.
removeExpireUserTargetDate
Removes the scheduled expiration for the user in the segment.
Parameters
targetType: A segment’s target type, must be eitherincludedorexcluded.userKey: The user key.
curl --request PATCH \
--url https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-user-targets/{environmentKey} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"instructions": [
{
"kind": "updateExpireUserTargetDate",
"targetType": "included",
"userKey": "user-key-123abc",
"value": 1587582000000,
"version": 0
}
],
"comment": "optional comment"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-user-targets/{environmentKey}"
payload = {
"instructions": [
{
"kind": "updateExpireUserTargetDate",
"targetType": "included",
"userKey": "user-key-123abc",
"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: [
{
kind: 'updateExpireUserTargetDate',
targetType: 'included',
userKey: 'user-key-123abc',
value: 1587582000000,
version: 0
}
],
comment: 'optional comment'
})
};
fetch('https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-user-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-user-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' => [
[
'kind' => 'updateExpireUserTargetDate',
'targetType' => 'included',
'userKey' => 'user-key-123abc',
'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-user-targets/{environmentKey}"
payload := strings.NewReader("{\n \"instructions\": [\n {\n \"kind\": \"updateExpireUserTargetDate\",\n \"targetType\": \"included\",\n \"userKey\": \"user-key-123abc\",\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-user-targets/{environmentKey}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"instructions\": [\n {\n \"kind\": \"updateExpireUserTargetDate\",\n \"targetType\": \"included\",\n \"userKey\": \"user-key-123abc\",\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-user-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 \"kind\": \"updateExpireUserTargetDate\",\n \"targetType\": \"included\",\n \"userKey\": \"user-key-123abc\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"_id": "12ab3c45de678910fgh12345",
"_version": 1,
"expirationDate": "1658192820000",
"userKey": "example-user-key",
"_resourceId": {
"kind": "<string>",
"projectKey": "<string>",
"environmentKey": "<string>",
"flagKey": "<string>",
"key": "<string>"
},
"targetType": "included",
"variationId": "ce67d625-a8b9-4fb5-a344-ab909d9d4f4d"
}
],
"_links": {},
"totalInstructions": 1,
"successfulInstructions": 1,
"failedInstructions": 0,
"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
[
{
"kind": "updateExpireUserTargetDate",
"targetType": "included",
"userKey": "user-key-123abc",
"value": 1587582000000,
"version": 0
}
]
Optional description of changes
"optional comment"
Response
Expiring user target response
An array of expiring user targets
Show child attributes
Show child attributes
The location and content type of related resources
Show child attributes
Show child attributes
The total count of instructions sent in the PATCH request
1
The total count of successful instructions sent in the PATCH request
1
The total count of the failed instructions sent in the PATCH request
0
An array of error messages for the failed instructions
Show child attributes
Show child attributes
curl --request PATCH \
--url https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-user-targets/{environmentKey} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"instructions": [
{
"kind": "updateExpireUserTargetDate",
"targetType": "included",
"userKey": "user-key-123abc",
"value": 1587582000000,
"version": 0
}
],
"comment": "optional comment"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-user-targets/{environmentKey}"
payload = {
"instructions": [
{
"kind": "updateExpireUserTargetDate",
"targetType": "included",
"userKey": "user-key-123abc",
"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: [
{
kind: 'updateExpireUserTargetDate',
targetType: 'included',
userKey: 'user-key-123abc',
value: 1587582000000,
version: 0
}
],
comment: 'optional comment'
})
};
fetch('https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-user-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-user-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' => [
[
'kind' => 'updateExpireUserTargetDate',
'targetType' => 'included',
'userKey' => 'user-key-123abc',
'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-user-targets/{environmentKey}"
payload := strings.NewReader("{\n \"instructions\": [\n {\n \"kind\": \"updateExpireUserTargetDate\",\n \"targetType\": \"included\",\n \"userKey\": \"user-key-123abc\",\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-user-targets/{environmentKey}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"instructions\": [\n {\n \"kind\": \"updateExpireUserTargetDate\",\n \"targetType\": \"included\",\n \"userKey\": \"user-key-123abc\",\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-user-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 \"kind\": \"updateExpireUserTargetDate\",\n \"targetType\": \"included\",\n \"userKey\": \"user-key-123abc\",\n \"value\": 1587582000000,\n \"version\": 0\n }\n ],\n \"comment\": \"optional comment\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"_id": "12ab3c45de678910fgh12345",
"_version": 1,
"expirationDate": "1658192820000",
"userKey": "example-user-key",
"_resourceId": {
"kind": "<string>",
"projectKey": "<string>",
"environmentKey": "<string>",
"flagKey": "<string>",
"key": "<string>"
},
"targetType": "included",
"variationId": "ce67d625-a8b9-4fb5-a344-ab909d9d4f4d"
}
],
"_links": {},
"totalInstructions": 1,
"successfulInstructions": 1,
"failedInstructions": 0,
"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."
}