---
title: "Update expiring targets for segment"
method: PATCH
path: "/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}"
tags: ["Segments"]
---

# Update expiring targets for segment

`PATCH /api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}`

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](https://launchdarkly.com/docs/api#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.

<details>
<summary>Click to expand instructions for <strong>updating expiring context targets</strong></summary>

#### 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 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.

Here's an example:

```json
{
  "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 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`: (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:

```json
{
  "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 either `included` or `excluded`.
- `contextKey`: The context key.
- `contextKind`: The kind of context being targeted.

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeExpiringTarget",
    "targetType": "included",
    "contextKey": "user-key-123abc",
    "contextKind": "user",
  }]
}
```

</details>

## Path parameters

- `projectKey` string, string, required — The project key
- `environmentKey` string, string, required — The environment key
- `segmentKey` string, string, required — The segment key

## Request body

- PatchSegmentExpiringTargetInputRep
  - `comment` string — Optional description of changes
  - `instructions` PatchSegmentExpiringTargetInstruction[], required — Semantic patch instructions for the desired changes to the resource
    - `kind` 'addExpiringTarget' | 'updateExpiringTarget' | 'removeExpiringTarget', required — The type of change to make to the context's removal date from this segment
    - `contextKey` string, required — A unique key used to represent the context
    - `contextKind` string, required — The kind of context
    - `targetType` 'included' | 'excluded', required — The segment's target type
    - `value` integer — The time, in Unix milliseconds, when the context should be removed from this segment. Required if <code>kind</code> is <code>addExpiringTarget</code> or <code>updateExpiringTarget</code>.
    - `version` integer — The version of the expiring target to update. Optional and only used if <code>kind</code> is <code>updateExpiringTarget</code>. If included, update will fail if version doesn't match current version of the expiring target.

## Response `200`

Expiring  target response

- ExpiringTargetPatchResponse
  - `items` ExpiringTarget[], required — A list of the results from each instruction
    - `_id` string, required — The ID of this expiring target
    - `_version` integer, required — The version of this expiring target
    - `expirationDate` integer, required
    - `contextKind` string, required — The context kind of the context to be removed
    - `contextKey` string, required — A unique key used to represent the context to be removed
    - `targetType` string — A segment's target type, <code>included</code> or <code>excluded</code>. Included when expiring targets are updated on a segment.
    - `variationId` string — A unique ID used to represent the flag variation. Included when expiring targets are updated on a feature flag.
    - `_resourceId` ResourceId, required
      - `environmentKey` string — The environment key
      - `flagKey` string — Deprecated, use <code>key</code> instead
      - `key` string — The key of the flag or segment
      - `kind` string
      - `projectKey` string — The project key
  - `_links` object — The location and content type of related resources
  - `totalInstructions` integer
  - `successfulInstructions` integer
  - `failedInstructions` integer
  - `errors` ExpiringTargetError[]
    - `instructionIndex` integer, required — The index of the PATCH instruction where the error occurred
    - `message` string, required — The error message related to a failed PATCH instruction

## Other responses

- `400` — Invalid request
- `401` — Invalid access token
- `403` — Forbidden
- `404` — Invalid resource identifier
- `409` — Status conflict
- `429` — Rate limited

---

[API](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api.md) · [All operations](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/launchdarkly/launchdarkly-rest-api/revisions/69c5c9aafe78/schema)
