---
title: "Update expiring context targets on feature flag"
method: PATCH
path: "/api/v2/flags/{projectKey}/{featureFlagKey}/expiring-targets/{environmentKey}"
tags: ["Feature flags"]
---

# Update expiring context targets on feature flag

`PATCH /api/v2/flags/{projectKey}/{featureFlagKey}/expiring-targets/{environmentKey}`

Schedule a context for removal from individual targeting on a feature flag. The flag must already individually target the context.

You can add, update, or remove a scheduled removal date. You can only schedule a context for removal on a single variation per flag.

Updating an expiring target 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).

### Instructions

Semantic patch requests support the following `kind` instructions for updating expiring targets.

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

#### addExpiringTarget

Adds a date and time that LaunchDarkly will remove the context from the flag's individual targeting.

##### Parameters

* `value`: The time, in Unix milliseconds, when LaunchDarkly should remove the context from individual targeting for this flag
* `variationId`: ID of a variation on the flag
* `contextKey`: The context key for the context to remove from individual targeting
* `contextKind`: The kind of context represented by the `contextKey`

Here's an example:

```json
{
  "instructions": [{
    "kind": "addExpiringTarget",
    "value": 1754006460000,
    "variationId": "4254742c-71ae-411f-a992-43b18a51afe0",
    "contextKey": "user-key-123abc",
    "contextKind": "user"
  }]
}
```

#### updateExpiringTarget

Updates the date and time that LaunchDarkly will remove the context from the flag's individual targeting

##### Parameters

* `value`: The time, in Unix milliseconds, when LaunchDarkly should remove the context from individual targeting for this flag
* `variationId`: ID of a variation on the flag
* `contextKey`: The context key for the context to remove from individual targeting
* `contextKind`: The kind of context represented by the `contextKey`
* `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",
    "value": 1754006460000,
    "variationId": "4254742c-71ae-411f-a992-43b18a51afe0",
    "contextKey": "user-key-123abc",
    "contextKind": "user"
  }]
}
```

#### removeExpiringTarget

Removes the scheduled removal of the context from the flag's individual targeting. The context will remain part of the flag's individual targeting until you explicitly remove it, or until you schedule another removal.

##### Parameters

* `variationId`: ID of a variation on the flag
* `contextKey`: The context key for the context to remove from individual targeting
* `contextKind`: The kind of context represented by the `contextKey`

Here's an example:

```json
{
  "instructions": [{
    "kind": "removeExpiringTarget",
    "variationId": "4254742c-71ae-411f-a992-43b18a51afe0",
    "contextKey": "user-key-123abc",
    "contextKind": "user"
  }]
}
```

</details>

## Path parameters

- `projectKey` string, string, required — The project key
- `environmentKey` string, string, required — The environment key
- `featureFlagKey` string, string, required — The feature flag key

## Request body

- PatchFlagsRequest
  - `comment` string — Optional comment describing the change
  - `instructions` Instruction[], required — The instructions to perform when updating

## 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
- `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)
