---
title: Update targeting rules for a flag
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Feature Flags
---

# Update targeting rules for a flag{% #update-targeting-rules-for-a-flag %}

{% tab title="v2" %}

| Datadog site      | API endpoint                                                                                                       |
| ----------------- | ------------------------------------------------------------------------------------------------------------------ |
| ap1.datadoghq.com | PUT https://api.ap1.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations |
| ap2.datadoghq.com | PUT https://api.ap2.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations |
| app.datadoghq.eu  | PUT https://api.datadoghq.eu/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations      |
| app.ddog-gov.com  | PUT https://api.ddog-gov.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations      |
| us2.ddog-gov.com  | PUT https://api.us2.ddog-gov.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations  |
| app.datadoghq.com | PUT https://api.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations     |
| us3.datadoghq.com | PUT https://api.us3.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations |
| us5.datadoghq.com | PUT https://api.us5.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations |

### Overview

Updates targeting rules (allocations) for a specific feature flag in a specific environment. This operation replaces the existing allocation set with the request payload. This endpoint requires the `feature_flag_config_write` permission.

### Arguments

#### Path Parameters

| Name                              | Type   | Description                 |
| --------------------------------- | ------ | --------------------------- |
| feature_flag_id [*required*] | string | The ID of the feature flag. |
| environment_id [*required*]  | string | The ID of the environment.  |

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field      | Field                                | Type      | Description                                                                                                                           |
| ----------------- | ------------------------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|                   | data [*required*]               | [object]  | Targeting rules (allocations) to replace existing ones with.                                                                          |
| data              | attributes [*required*]         | object    | Request to create or update a targeting rule (allocation) for a feature flag environment.                                             |
| attributes        | experiment_id                        | string    | The experiment ID for experiment-linked allocations.                                                                                  |
| attributes        | exposure_schedule                    | object    | Progressive release request payload.                                                                                                  |
| exposure_schedule | absolute_start_time                  | date-time | The absolute UTC start time for this schedule.                                                                                        |
| exposure_schedule | control_variant_id                   | string    | The control variant ID used for experiment comparisons.                                                                               |
| exposure_schedule | control_variant_key                  | string    | The control variant key used during creation workflows.                                                                               |
| exposure_schedule | id                                   | uuid      | The unique identifier of the progressive rollout.                                                                                     |
| exposure_schedule | rollout_options [*required*]    | object    | Rollout options request payload.                                                                                                      |
| rollout_options   | autostart                            | boolean   | Whether the schedule should begin automatically.                                                                                      |
| rollout_options   | selection_interval_ms                | int64     | Interval in milliseconds for uniform interval strategies.                                                                             |
| rollout_options   | strategy [*required*]           | enum      | The progression strategy used by a progressive rollout. Allowed enum values: `UNIFORM_INTERVALS,NO_ROLLOUT`                           |
| exposure_schedule | rollout_steps [*required*]      | [object]  | Ordered progression steps for exposure.                                                                                               |
| rollout_steps     | exposure_ratio [*required*]     | double    | The exposure ratio for this step.                                                                                                     |
| rollout_steps     | grouped_step_index [*required*] | int64     | Logical index grouping related steps.                                                                                                 |
| rollout_steps     | id                                   | uuid      | The unique identifier of the progression step.                                                                                        |
| rollout_steps     | interval_ms                          | int64     | Step duration in milliseconds.                                                                                                        |
| rollout_steps     | is_pause_record [*required*]    | boolean   | Whether this step represents a pause record.                                                                                          |
| attributes        | guardrail_metrics                    | [object]  | Guardrail metrics used to monitor and auto-pause or abort.                                                                            |
| guardrail_metrics | metric_id [*required*]          | string    | The metric ID to monitor.                                                                                                             |
| guardrail_metrics | trigger_action [*required*]     | enum      | Action to perform when a guardrail threshold is triggered. Allowed enum values: `PAUSE,ABORT`                                         |
| attributes        | id                                   | uuid      | The unique identifier of the targeting rule allocation.                                                                               |
| attributes        | key [*required*]                | string    | The unique key of the targeting rule allocation.                                                                                      |
| attributes        | name [*required*]               | string    | The display name of the targeting rule.                                                                                               |
| attributes        | targeting_rules                      | [object]  | Targeting rules that determine audience eligibility.                                                                                  |
| targeting_rules   | conditions [*required*]         | [object]  | Conditions that must match for this rule.                                                                                             |
| conditions        | attribute [*required*]          | string    | The user or request attribute to evaluate.                                                                                            |
| conditions        | operator [*required*]           | enum      | The operator used in a targeting condition. Allowed enum values: `LT,LTE,GT,GTE,MATCHES,NOT_MATCHES,ONE_OF,NOT_ONE_OF,IS_NULL,EQUALS` |
| conditions        | value [*required*]              | [string]  | Values used by the selected operator.                                                                                                 |
| attributes        | type [*required*]               | enum      | The type of targeting rule (called allocation in the API model). Allowed enum values: `FEATURE_GATE,CANARY`                           |
| attributes        | variant_weights                      | [object]  | Variant distribution weights.                                                                                                         |
| variant_weights   | value [*required*]              | double    | The percentage weight for this variant.                                                                                               |
| variant_weights   | variant_id                           | uuid      | The variant ID to assign weight to.                                                                                                   |
| variant_weights   | variant_key                          | string    | The variant key to assign weight to.                                                                                                  |
| data              | type [*required*]               | enum      | The resource type. Allowed enum values: `allocations`                                                                                 |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": [
    {
      "type": "allocations",
      "attributes": {
        "key": "overwrite-allocation-example-feature-flag",
        "name": "New targeting rule Example-Feature-Flag",
        "targeting_rules": [],
        "variant_weights": [
          {
            "variant_id": "550e8400-e29b-41d4-a716-446655440002",
            "value": 100
          }
        ],
        "exposure_schedule": {
          "rollout_options": {
            "strategy": "UNIFORM_INTERVALS",
            "autostart": false,
            "selection_interval_ms": 86400000
          },
          "rollout_steps": [
            {
              "exposure_ratio": 0.05,
              "interval_ms": null,
              "is_pause_record": false,
              "grouped_step_index": 0
            },
            {
              "exposure_ratio": 0.25,
              "interval_ms": null,
              "is_pause_record": false,
              "grouped_step_index": 1
            },
            {
              "exposure_ratio": 1,
              "interval_ms": null,
              "is_pause_record": false,
              "grouped_step_index": 2
            }
          ]
        },
        "guardrail_metrics": [],
        "type": "CANARY"
      }
    }
  ]
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Response containing a list of targeting rules (allocations).

| Parent field       | Field                                             | Type      | Description                                                                                                                           |
| ------------------ | ------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|                    | data [*required*]                            | [object]  | List of targeting rules (allocations).                                                                                                |
| data               | attributes [*required*]                      | object    | Targeting rule (allocation) details for a feature flag environment.                                                                   |
| attributes         | created_at [*required*]                      | date-time | The timestamp when the targeting rule allocation was created.                                                                         |
| attributes         | environment_ids [*required*]                 | [string]  | Environment IDs associated with this targeting rule allocation.                                                                       |
| attributes         | experiment_id                                     | string    | The experiment ID linked to this targeting rule allocation.                                                                           |
| attributes         | exposure_schedule                                 | object    | Progressive release details for a targeting rule allocation.                                                                          |
| exposure_schedule  | absolute_start_time                               | date-time | The absolute UTC start time for this schedule.                                                                                        |
| exposure_schedule  | allocation_id [*required*]                   | uuid      | The targeting rule allocation ID this progressive rollout belongs to.                                                                 |
| exposure_schedule  | control_variant_id                                | string    | The control variant ID used for experiment comparisons.                                                                               |
| exposure_schedule  | created_at [*required*]                      | date-time | The timestamp when the schedule was created.                                                                                          |
| exposure_schedule  | guardrail_triggered_action                        | string    | Last guardrail action triggered for this schedule.                                                                                    |
| exposure_schedule  | guardrail_triggers [*required*]              | [object]  | Guardrail trigger records for this schedule.                                                                                          |
| guardrail_triggers | allocation_exposure_schedule_id [*required*] | uuid      | The progressive rollout ID this trigger belongs to.                                                                                   |
| guardrail_triggers | created_at [*required*]                      | date-time | The timestamp when this trigger was created.                                                                                          |
| guardrail_triggers | flagging_variant_id [*required*]             | uuid      | The variant ID that triggered this event.                                                                                             |
| guardrail_triggers | id [*required*]                              | uuid      | The unique identifier of the guardrail trigger.                                                                                       |
| guardrail_triggers | metric_id [*required*]                       | string    | The metric ID associated with the trigger.                                                                                            |
| guardrail_triggers | triggered_action [*required*]                | string    | The action that was triggered.                                                                                                        |
| guardrail_triggers | updated_at [*required*]                      | date-time | The timestamp when this trigger was last updated.                                                                                     |
| exposure_schedule  | id                                                | uuid      | The unique identifier of the progressive rollout.                                                                                     |
| exposure_schedule  | rollout_options [*required*]                 | object    | Applied progression options for a progressive rollout.                                                                                |
| rollout_options    | autostart [*required*]                       | boolean   | Whether the schedule starts automatically.                                                                                            |
| rollout_options    | selection_interval_ms [*required*]           | int64     | Interval in milliseconds for uniform interval strategies.                                                                             |
| rollout_options    | strategy [*required*]                        | enum      | The progression strategy used by a progressive rollout. Allowed enum values: `UNIFORM_INTERVALS,NO_ROLLOUT`                           |
| exposure_schedule  | rollout_steps [*required*]                   | [object]  | Ordered progression steps for exposure.                                                                                               |
| rollout_steps      | allocation_exposure_schedule_id [*required*] | uuid      | The progressive rollout ID this step belongs to.                                                                                      |
| rollout_steps      | created_at [*required*]                      | date-time | The timestamp when the progression step was created.                                                                                  |
| rollout_steps      | exposure_ratio [*required*]                  | double    | The exposure ratio for this step.                                                                                                     |
| rollout_steps      | grouped_step_index [*required*]              | int64     | Logical index grouping related steps.                                                                                                 |
| rollout_steps      | id [*required*]                              | uuid      | The unique identifier of the progression step.                                                                                        |
| rollout_steps      | interval_ms                                       | int64     | Step duration in milliseconds.                                                                                                        |
| rollout_steps      | is_pause_record [*required*]                 | boolean   | Whether this step represents a pause record.                                                                                          |
| rollout_steps      | order_position [*required*]                  | int64     | Sort order for the progression step.                                                                                                  |
| rollout_steps      | updated_at [*required*]                      | date-time | The timestamp when the progression step was last updated.                                                                             |
| exposure_schedule  | updated_at [*required*]                      | date-time | The timestamp when the schedule was last updated.                                                                                     |
| attributes         | guardrail_metrics [*required*]               | [object]  | Guardrail metrics associated with this targeting rule allocation.                                                                     |
| guardrail_metrics  | metric_id [*required*]                       | string    | The metric ID to monitor.                                                                                                             |
| guardrail_metrics  | trigger_action [*required*]                  | enum      | Action to perform when a guardrail threshold is triggered. Allowed enum values: `PAUSE,ABORT`                                         |
| guardrail_metrics  | triggered_by                                      | string    | The signal or system that triggered the action.                                                                                       |
| attributes         | id                                                | uuid      | The unique identifier of the targeting rule allocation.                                                                               |
| attributes         | key [*required*]                             | string    | The unique key of the targeting rule allocation.                                                                                      |
| attributes         | name [*required*]                            | string    | The display name of the targeting rule.                                                                                               |
| attributes         | order_position [*required*]                  | int64     | Sort order position within the environment.                                                                                           |
| attributes         | targeting_rules [*required*]                 | [object]  | Conditions associated with this targeting rule allocation.                                                                            |
| targeting_rules    | conditions [*required*]                      | [object]  | Conditions evaluated by this targeting rule.                                                                                          |
| conditions         | attribute [*required*]                       | string    | The user or request attribute to evaluate.                                                                                            |
| conditions         | created_at [*required*]                      | date-time | The timestamp when the condition was created.                                                                                         |
| conditions         | id [*required*]                              | uuid      | The unique identifier of the condition.                                                                                               |
| conditions         | operator [*required*]                        | enum      | The operator used in a targeting condition. Allowed enum values: `LT,LTE,GT,GTE,MATCHES,NOT_MATCHES,ONE_OF,NOT_ONE_OF,IS_NULL,EQUALS` |
| conditions         | updated_at [*required*]                      | date-time | The timestamp when the condition was last updated.                                                                                    |
| conditions         | value [*required*]                           | [string]  | Values used by the selected operator.                                                                                                 |
| targeting_rules    | created_at [*required*]                      | date-time | The timestamp when the targeting rule was created.                                                                                    |
| targeting_rules    | id [*required*]                              | uuid      | The unique identifier of the targeting rule.                                                                                          |
| targeting_rules    | updated_at [*required*]                      | date-time | The timestamp when the targeting rule was last updated.                                                                               |
| attributes         | type [*required*]                            | enum      | The type of targeting rule (called allocation in the API model). Allowed enum values: `FEATURE_GATE,CANARY`                           |
| attributes         | updated_at [*required*]                      | date-time | The timestamp when the targeting rule allocation was last updated.                                                                    |
| attributes         | variant_weights [*required*]                 | [object]  | Weighted variant assignments for this targeting rule allocation.                                                                      |
| variant_weights    | created_at                                        | date-time | The timestamp when the variant weight was created.                                                                                    |
| variant_weights    | id                                                | uuid      | Unique identifier of the variant weight assignment.                                                                                   |
| variant_weights    | updated_at                                        | date-time | The timestamp when the variant weight was last updated.                                                                               |
| variant_weights    | value [*required*]                           | double    | The percentage weight for the variant.                                                                                                |
| variant_weights    | variant                                           | object    | A variant of a feature flag.                                                                                                          |
| variant            | created_at                                        | date-time | The timestamp when the variant was created.                                                                                           |
| variant            | id [*required*]                              | uuid      | The unique identifier of the variant.                                                                                                 |
| variant            | key [*required*]                             | string    | The unique key of the variant.                                                                                                        |
| variant            | name [*required*]                            | string    | The name of the variant.                                                                                                              |
| variant            | updated_at                                        | date-time | The timestamp when the variant was last updated.                                                                                      |
| variant            | value [*required*]                           | string    | The value of the variant as a string.                                                                                                 |
| variant_weights    | variant_id [*required*]                      | uuid      | The variant ID.                                                                                                                       |
| data               | id [*required*]                              | uuid      | The unique identifier of the targeting rule allocation.                                                                               |
| data               | type [*required*]                            | enum      | The resource type. Allowed enum values: `allocations`                                                                                 |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": [
    {
      "attributes": {
        "created_at": "2024-01-01T12:00:00Z",
        "environment_ids": [
          "550e8400-e29b-41d4-a716-446655440001"
        ],
        "experiment_id": "550e8400-e29b-41d4-a716-446655440030",
        "exposure_schedule": {
          "absolute_start_time": "2025-06-13T12:00:00Z",
          "allocation_id": "550e8400-e29b-41d4-a716-446655440020",
          "control_variant_id": "550e8400-e29b-41d4-a716-446655440012",
          "created_at": "2024-01-01T12:00:00Z",
          "guardrail_triggered_action": "PAUSE",
          "guardrail_triggers": [
            {
              "allocation_exposure_schedule_id": "550e8400-e29b-41d4-a716-446655440010",
              "created_at": "2024-01-01T12:00:00Z",
              "flagging_variant_id": "550e8400-e29b-41d4-a716-446655440001",
              "id": "550e8400-e29b-41d4-a716-446655440080",
              "metric_id": "metric-error-rate",
              "triggered_action": "PAUSE",
              "updated_at": "2024-01-01T12:00:00Z"
            }
          ],
          "id": "550e8400-e29b-41d4-a716-446655440010",
          "rollout_options": {
            "autostart": false,
            "selection_interval_ms": 3600000,
            "strategy": "UNIFORM_INTERVALS"
          },
          "rollout_steps": [
            {
              "allocation_exposure_schedule_id": "550e8400-e29b-41d4-a716-446655440010",
              "created_at": "2024-01-01T12:00:00Z",
              "exposure_ratio": 0.1,
              "grouped_step_index": 0,
              "id": "550e8400-e29b-41d4-a716-446655440040",
              "interval_ms": 3600000,
              "is_pause_record": false,
              "order_position": 0,
              "updated_at": "2024-01-01T12:00:00Z"
            }
          ],
          "updated_at": "2024-01-01T12:00:00Z"
        },
        "guardrail_metrics": [
          {
            "metric_id": "metric-error-rate",
            "trigger_action": "PAUSE",
            "triggered_by": "guardrail_monitor"
          }
        ],
        "id": "550e8400-e29b-41d4-a716-446655440020",
        "key": "prod-rollout",
        "name": "Production Rollout",
        "order_position": 0,
        "targeting_rules": [
          {
            "conditions": [
              {
                "attribute": "country",
                "created_at": "2024-01-01T12:00:00Z",
                "id": "550e8400-e29b-41d4-a716-446655440070",
                "operator": "ONE_OF",
                "updated_at": "2024-01-01T12:00:00Z",
                "value": [
                  "US",
                  "CA"
                ]
              }
            ],
            "created_at": "2024-01-01T12:00:00Z",
            "id": "550e8400-e29b-41d4-a716-446655440060",
            "updated_at": "2024-01-01T12:00:00Z"
          }
        ],
        "type": "FEATURE_GATE",
        "updated_at": "2024-01-01T12:00:00Z",
        "variant_weights": [
          {
            "created_at": "2024-01-01T12:00:00Z",
            "id": "59061199-e2ff-46e9-8b40-2193e3b21687",
            "updated_at": "2024-01-01T12:00:00Z",
            "value": 50,
            "variant": {
              "created_at": "2023-01-01T00:00:00Z",
              "id": "550e8400-e29b-41d4-a716-446655440002",
              "key": "variant-abc123",
              "name": "Variant ABC123",
              "updated_at": "2023-01-01T00:00:00Z",
              "value": "true"
            },
            "variant_id": "550e8400-e29b-41d4-a716-446655440001"
          }
        ]
      },
      "id": "550e8400-e29b-41d4-a716-446655440020",
      "type": "allocations"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="202" %}
Accepted - Approval required for this change
{% tab title="Model" %}
Response containing a list of targeting rules (allocations).

| Parent field       | Field                                             | Type      | Description                                                                                                                           |
| ------------------ | ------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|                    | data [*required*]                            | [object]  | List of targeting rules (allocations).                                                                                                |
| data               | attributes [*required*]                      | object    | Targeting rule (allocation) details for a feature flag environment.                                                                   |
| attributes         | created_at [*required*]                      | date-time | The timestamp when the targeting rule allocation was created.                                                                         |
| attributes         | environment_ids [*required*]                 | [string]  | Environment IDs associated with this targeting rule allocation.                                                                       |
| attributes         | experiment_id                                     | string    | The experiment ID linked to this targeting rule allocation.                                                                           |
| attributes         | exposure_schedule                                 | object    | Progressive release details for a targeting rule allocation.                                                                          |
| exposure_schedule  | absolute_start_time                               | date-time | The absolute UTC start time for this schedule.                                                                                        |
| exposure_schedule  | allocation_id [*required*]                   | uuid      | The targeting rule allocation ID this progressive rollout belongs to.                                                                 |
| exposure_schedule  | control_variant_id                                | string    | The control variant ID used for experiment comparisons.                                                                               |
| exposure_schedule  | created_at [*required*]                      | date-time | The timestamp when the schedule was created.                                                                                          |
| exposure_schedule  | guardrail_triggered_action                        | string    | Last guardrail action triggered for this schedule.                                                                                    |
| exposure_schedule  | guardrail_triggers [*required*]              | [object]  | Guardrail trigger records for this schedule.                                                                                          |
| guardrail_triggers | allocation_exposure_schedule_id [*required*] | uuid      | The progressive rollout ID this trigger belongs to.                                                                                   |
| guardrail_triggers | created_at [*required*]                      | date-time | The timestamp when this trigger was created.                                                                                          |
| guardrail_triggers | flagging_variant_id [*required*]             | uuid      | The variant ID that triggered this event.                                                                                             |
| guardrail_triggers | id [*required*]                              | uuid      | The unique identifier of the guardrail trigger.                                                                                       |
| guardrail_triggers | metric_id [*required*]                       | string    | The metric ID associated with the trigger.                                                                                            |
| guardrail_triggers | triggered_action [*required*]                | string    | The action that was triggered.                                                                                                        |
| guardrail_triggers | updated_at [*required*]                      | date-time | The timestamp when this trigger was last updated.                                                                                     |
| exposure_schedule  | id                                                | uuid      | The unique identifier of the progressive rollout.                                                                                     |
| exposure_schedule  | rollout_options [*required*]                 | object    | Applied progression options for a progressive rollout.                                                                                |
| rollout_options    | autostart [*required*]                       | boolean   | Whether the schedule starts automatically.                                                                                            |
| rollout_options    | selection_interval_ms [*required*]           | int64     | Interval in milliseconds for uniform interval strategies.                                                                             |
| rollout_options    | strategy [*required*]                        | enum      | The progression strategy used by a progressive rollout. Allowed enum values: `UNIFORM_INTERVALS,NO_ROLLOUT`                           |
| exposure_schedule  | rollout_steps [*required*]                   | [object]  | Ordered progression steps for exposure.                                                                                               |
| rollout_steps      | allocation_exposure_schedule_id [*required*] | uuid      | The progressive rollout ID this step belongs to.                                                                                      |
| rollout_steps      | created_at [*required*]                      | date-time | The timestamp when the progression step was created.                                                                                  |
| rollout_steps      | exposure_ratio [*required*]                  | double    | The exposure ratio for this step.                                                                                                     |
| rollout_steps      | grouped_step_index [*required*]              | int64     | Logical index grouping related steps.                                                                                                 |
| rollout_steps      | id [*required*]                              | uuid      | The unique identifier of the progression step.                                                                                        |
| rollout_steps      | interval_ms                                       | int64     | Step duration in milliseconds.                                                                                                        |
| rollout_steps      | is_pause_record [*required*]                 | boolean   | Whether this step represents a pause record.                                                                                          |
| rollout_steps      | order_position [*required*]                  | int64     | Sort order for the progression step.                                                                                                  |
| rollout_steps      | updated_at [*required*]                      | date-time | The timestamp when the progression step was last updated.                                                                             |
| exposure_schedule  | updated_at [*required*]                      | date-time | The timestamp when the schedule was last updated.                                                                                     |
| attributes         | guardrail_metrics [*required*]               | [object]  | Guardrail metrics associated with this targeting rule allocation.                                                                     |
| guardrail_metrics  | metric_id [*required*]                       | string    | The metric ID to monitor.                                                                                                             |
| guardrail_metrics  | trigger_action [*required*]                  | enum      | Action to perform when a guardrail threshold is triggered. Allowed enum values: `PAUSE,ABORT`                                         |
| guardrail_metrics  | triggered_by                                      | string    | The signal or system that triggered the action.                                                                                       |
| attributes         | id                                                | uuid      | The unique identifier of the targeting rule allocation.                                                                               |
| attributes         | key [*required*]                             | string    | The unique key of the targeting rule allocation.                                                                                      |
| attributes         | name [*required*]                            | string    | The display name of the targeting rule.                                                                                               |
| attributes         | order_position [*required*]                  | int64     | Sort order position within the environment.                                                                                           |
| attributes         | targeting_rules [*required*]                 | [object]  | Conditions associated with this targeting rule allocation.                                                                            |
| targeting_rules    | conditions [*required*]                      | [object]  | Conditions evaluated by this targeting rule.                                                                                          |
| conditions         | attribute [*required*]                       | string    | The user or request attribute to evaluate.                                                                                            |
| conditions         | created_at [*required*]                      | date-time | The timestamp when the condition was created.                                                                                         |
| conditions         | id [*required*]                              | uuid      | The unique identifier of the condition.                                                                                               |
| conditions         | operator [*required*]                        | enum      | The operator used in a targeting condition. Allowed enum values: `LT,LTE,GT,GTE,MATCHES,NOT_MATCHES,ONE_OF,NOT_ONE_OF,IS_NULL,EQUALS` |
| conditions         | updated_at [*required*]                      | date-time | The timestamp when the condition was last updated.                                                                                    |
| conditions         | value [*required*]                           | [string]  | Values used by the selected operator.                                                                                                 |
| targeting_rules    | created_at [*required*]                      | date-time | The timestamp when the targeting rule was created.                                                                                    |
| targeting_rules    | id [*required*]                              | uuid      | The unique identifier of the targeting rule.                                                                                          |
| targeting_rules    | updated_at [*required*]                      | date-time | The timestamp when the targeting rule was last updated.                                                                               |
| attributes         | type [*required*]                            | enum      | The type of targeting rule (called allocation in the API model). Allowed enum values: `FEATURE_GATE,CANARY`                           |
| attributes         | updated_at [*required*]                      | date-time | The timestamp when the targeting rule allocation was last updated.                                                                    |
| attributes         | variant_weights [*required*]                 | [object]  | Weighted variant assignments for this targeting rule allocation.                                                                      |
| variant_weights    | created_at                                        | date-time | The timestamp when the variant weight was created.                                                                                    |
| variant_weights    | id                                                | uuid      | Unique identifier of the variant weight assignment.                                                                                   |
| variant_weights    | updated_at                                        | date-time | The timestamp when the variant weight was last updated.                                                                               |
| variant_weights    | value [*required*]                           | double    | The percentage weight for the variant.                                                                                                |
| variant_weights    | variant                                           | object    | A variant of a feature flag.                                                                                                          |
| variant            | created_at                                        | date-time | The timestamp when the variant was created.                                                                                           |
| variant            | id [*required*]                              | uuid      | The unique identifier of the variant.                                                                                                 |
| variant            | key [*required*]                             | string    | The unique key of the variant.                                                                                                        |
| variant            | name [*required*]                            | string    | The name of the variant.                                                                                                              |
| variant            | updated_at                                        | date-time | The timestamp when the variant was last updated.                                                                                      |
| variant            | value [*required*]                           | string    | The value of the variant as a string.                                                                                                 |
| variant_weights    | variant_id [*required*]                      | uuid      | The variant ID.                                                                                                                       |
| data               | id [*required*]                              | uuid      | The unique identifier of the targeting rule allocation.                                                                               |
| data               | type [*required*]                            | enum      | The resource type. Allowed enum values: `allocations`                                                                                 |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": [
    {
      "attributes": {
        "created_at": "2024-01-01T12:00:00Z",
        "environment_ids": [
          "550e8400-e29b-41d4-a716-446655440001"
        ],
        "experiment_id": "550e8400-e29b-41d4-a716-446655440030",
        "exposure_schedule": {
          "absolute_start_time": "2025-06-13T12:00:00Z",
          "allocation_id": "550e8400-e29b-41d4-a716-446655440020",
          "control_variant_id": "550e8400-e29b-41d4-a716-446655440012",
          "created_at": "2024-01-01T12:00:00Z",
          "guardrail_triggered_action": "PAUSE",
          "guardrail_triggers": [
            {
              "allocation_exposure_schedule_id": "550e8400-e29b-41d4-a716-446655440010",
              "created_at": "2024-01-01T12:00:00Z",
              "flagging_variant_id": "550e8400-e29b-41d4-a716-446655440001",
              "id": "550e8400-e29b-41d4-a716-446655440080",
              "metric_id": "metric-error-rate",
              "triggered_action": "PAUSE",
              "updated_at": "2024-01-01T12:00:00Z"
            }
          ],
          "id": "550e8400-e29b-41d4-a716-446655440010",
          "rollout_options": {
            "autostart": false,
            "selection_interval_ms": 3600000,
            "strategy": "UNIFORM_INTERVALS"
          },
          "rollout_steps": [
            {
              "allocation_exposure_schedule_id": "550e8400-e29b-41d4-a716-446655440010",
              "created_at": "2024-01-01T12:00:00Z",
              "exposure_ratio": 0.1,
              "grouped_step_index": 0,
              "id": "550e8400-e29b-41d4-a716-446655440040",
              "interval_ms": 3600000,
              "is_pause_record": false,
              "order_position": 0,
              "updated_at": "2024-01-01T12:00:00Z"
            }
          ],
          "updated_at": "2024-01-01T12:00:00Z"
        },
        "guardrail_metrics": [
          {
            "metric_id": "metric-error-rate",
            "trigger_action": "PAUSE",
            "triggered_by": "guardrail_monitor"
          }
        ],
        "id": "550e8400-e29b-41d4-a716-446655440020",
        "key": "prod-rollout",
        "name": "Production Rollout",
        "order_position": 0,
        "targeting_rules": [
          {
            "conditions": [
              {
                "attribute": "country",
                "created_at": "2024-01-01T12:00:00Z",
                "id": "550e8400-e29b-41d4-a716-446655440070",
                "operator": "ONE_OF",
                "updated_at": "2024-01-01T12:00:00Z",
                "value": [
                  "US",
                  "CA"
                ]
              }
            ],
            "created_at": "2024-01-01T12:00:00Z",
            "id": "550e8400-e29b-41d4-a716-446655440060",
            "updated_at": "2024-01-01T12:00:00Z"
          }
        ],
        "type": "FEATURE_GATE",
        "updated_at": "2024-01-01T12:00:00Z",
        "variant_weights": [
          {
            "created_at": "2024-01-01T12:00:00Z",
            "id": "59061199-e2ff-46e9-8b40-2193e3b21687",
            "updated_at": "2024-01-01T12:00:00Z",
            "value": 50,
            "variant": {
              "created_at": "2023-01-01T00:00:00Z",
              "id": "550e8400-e29b-41d4-a716-446655440002",
              "key": "variant-abc123",
              "name": "Variant ABC123",
              "updated_at": "2023-01-01T00:00:00Z",
              "value": "true"
            },
            "variant_id": "550e8400-e29b-41d4-a716-446655440001"
          }
        ]
      },
      "id": "550e8400-e29b-41d4-a716-446655440020",
      "type": "allocations"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="403" %}
Forbidden
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="404" %}
Not Found
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="409" %}
Conflict
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                          \## default
# 
 \# Path parameters export feature_flag_id="550e8400-e29b-41d4-a716-446655440000" export environment_id="550e8400-e29b-41d4-a716-446655440001" \# Curl command curl -X PUT "https://api.datadoghq.com/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "data": [
    {
      "attributes": {
        "key": "prod-rollout",
        "name": "Production Rollout",
        "type": "FEATURE_GATE",
        "variant_weights": [
          {
            "value": 50,
            "variant_id": "550e8400-e29b-41d4-a716-446655440001"
          },
          {
            "value": 50,
            "variant_id": "550e8400-e29b-41d4-a716-446655440002"
          }
        ]
      },
      "type": "allocations"
    }
  ]
}
EOF 
                        
##### 

```go
// Update targeting rules for a flag in an environment returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
	"github.com/google/uuid"
)

func main() {
	// there is a valid "feature_flag" in the system
	FeatureFlagDataAttributesVariants0ID := uuid.MustParse(os.Getenv("FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID"))
	FeatureFlagDataID := uuid.MustParse(os.Getenv("FEATURE_FLAG_DATA_ID"))

	// there is a valid "environment" in the system
	EnvironmentDataID := uuid.MustParse(os.Getenv("ENVIRONMENT_DATA_ID"))

	body := datadogV2.OverwriteAllocationsRequest{
		Data: []datadogV2.AllocationDataRequest{
			{
				Type: datadogV2.ALLOCATIONDATATYPE_ALLOCATIONS,
				Attributes: datadogV2.UpsertAllocationRequest{
					Key:            "overwrite-allocation-example-feature-flag",
					Name:           "New targeting rule Example-Feature-Flag",
					TargetingRules: []datadogV2.TargetingRuleRequest{},
					VariantWeights: []datadogV2.VariantWeightRequest{
						{
							VariantId: datadog.PtrUUID(FeatureFlagDataAttributesVariants0ID),
							Value:     100,
						},
					},
					ExposureSchedule: &datadogV2.ExposureScheduleRequest{
						RolloutOptions: datadogV2.RolloutOptionsRequest{
							Strategy:            datadogV2.ROLLOUTSTRATEGY_UNIFORM_INTERVALS,
							Autostart:           *datadog.NewNullableBool(datadog.PtrBool(false)),
							SelectionIntervalMs: datadog.PtrInt64(86400000),
						},
						RolloutSteps: []datadogV2.ExposureRolloutStepRequest{
							{
								ExposureRatio:    0.05,
								IntervalMs:       *datadog.NewNullableInt64(nil),
								IsPauseRecord:    false,
								GroupedStepIndex: 0,
							},
							{
								ExposureRatio:    0.25,
								IntervalMs:       *datadog.NewNullableInt64(nil),
								IsPauseRecord:    false,
								GroupedStepIndex: 1,
							},
							{
								ExposureRatio:    1,
								IntervalMs:       *datadog.NewNullableInt64(nil),
								IsPauseRecord:    false,
								GroupedStepIndex: 2,
							},
						},
					},
					GuardrailMetrics: []datadogV2.GuardrailMetricRequest{},
					Type:             datadogV2.ALLOCATIONTYPE_CANARY,
				},
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewFeatureFlagsApi(apiClient)
	resp, r, err := api.UpdateAllocationsForFeatureFlagInEnvironment(ctx, FeatureFlagDataID, EnvironmentDataID, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `FeatureFlagsApi.UpdateAllocationsForFeatureFlagInEnvironment`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `FeatureFlagsApi.UpdateAllocationsForFeatureFlagInEnvironment`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
##### 

```java
// Update targeting rules for a flag in an environment returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.FeatureFlagsApi;
import com.datadog.api.client.v2.model.AllocationDataRequest;
import com.datadog.api.client.v2.model.AllocationDataType;
import com.datadog.api.client.v2.model.AllocationType;
import com.datadog.api.client.v2.model.ExposureRolloutStepRequest;
import com.datadog.api.client.v2.model.ExposureScheduleRequest;
import com.datadog.api.client.v2.model.ListAllocationsResponse;
import com.datadog.api.client.v2.model.OverwriteAllocationsRequest;
import com.datadog.api.client.v2.model.RolloutOptionsRequest;
import com.datadog.api.client.v2.model.RolloutStrategy;
import com.datadog.api.client.v2.model.UpsertAllocationRequest;
import com.datadog.api.client.v2.model.VariantWeightRequest;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    FeatureFlagsApi apiInstance = new FeatureFlagsApi(defaultClient);

    // there is a valid "feature_flag" in the system
    UUID FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID = null;
    try {
      FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID =
          UUID.fromString(System.getenv("FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID"));
    } catch (IllegalArgumentException e) {
      System.err.println("Error parsing UUID: " + e.getMessage());
    }
    UUID FEATURE_FLAG_DATA_ID = null;
    try {
      FEATURE_FLAG_DATA_ID = UUID.fromString(System.getenv("FEATURE_FLAG_DATA_ID"));
    } catch (IllegalArgumentException e) {
      System.err.println("Error parsing UUID: " + e.getMessage());
    }

    // there is a valid "environment" in the system
    UUID ENVIRONMENT_DATA_ID = null;
    try {
      ENVIRONMENT_DATA_ID = UUID.fromString(System.getenv("ENVIRONMENT_DATA_ID"));
    } catch (IllegalArgumentException e) {
      System.err.println("Error parsing UUID: " + e.getMessage());
    }

    OverwriteAllocationsRequest body =
        new OverwriteAllocationsRequest()
            .data(
                Collections.singletonList(
                    new AllocationDataRequest()
                        .type(AllocationDataType.ALLOCATIONS)
                        .attributes(
                            new UpsertAllocationRequest()
                                .key("overwrite-allocation-example-feature-flag")
                                .name("New targeting rule Example-Feature-Flag")
                                .variantWeights(
                                    Collections.singletonList(
                                        new VariantWeightRequest()
                                            .variantId(FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID)
                                            .value(100.0)))
                                .exposureSchedule(
                                    new ExposureScheduleRequest()
                                        .rolloutOptions(
                                            new RolloutOptionsRequest()
                                                .strategy(RolloutStrategy.UNIFORM_INTERVALS)
                                                .autostart(false)
                                                .selectionIntervalMs(86400000L))
                                        .rolloutSteps(
                                            Arrays.asList(
                                                new ExposureRolloutStepRequest()
                                                    .exposureRatio(0.05)
                                                    .intervalMs(null)
                                                    .isPauseRecord(false)
                                                    .groupedStepIndex(0L),
                                                new ExposureRolloutStepRequest()
                                                    .exposureRatio(0.25)
                                                    .intervalMs(null)
                                                    .isPauseRecord(false)
                                                    .groupedStepIndex(1L),
                                                new ExposureRolloutStepRequest()
                                                    .exposureRatio(1.0)
                                                    .intervalMs(null)
                                                    .isPauseRecord(false)
                                                    .groupedStepIndex(2L))))
                                .type(AllocationType.CANARY))));

    try {
      ListAllocationsResponse result =
          apiInstance.updateAllocationsForFeatureFlagInEnvironment(
              FEATURE_FLAG_DATA_ID, ENVIRONMENT_DATA_ID, body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling FeatureFlagsApi#updateAllocationsForFeatureFlagInEnvironment");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
##### 

```python
"""
Update targeting rules for a flag in an environment returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.feature_flags_api import FeatureFlagsApi
from datadog_api_client.v2.model.allocation_data_request import AllocationDataRequest
from datadog_api_client.v2.model.allocation_data_type import AllocationDataType
from datadog_api_client.v2.model.allocation_type import AllocationType
from datadog_api_client.v2.model.exposure_rollout_step_request import ExposureRolloutStepRequest
from datadog_api_client.v2.model.exposure_schedule_request import ExposureScheduleRequest
from datadog_api_client.v2.model.overwrite_allocations_request import OverwriteAllocationsRequest
from datadog_api_client.v2.model.rollout_options_request import RolloutOptionsRequest
from datadog_api_client.v2.model.rollout_strategy import RolloutStrategy
from datadog_api_client.v2.model.upsert_allocation_request import UpsertAllocationRequest
from datadog_api_client.v2.model.variant_weight_request import VariantWeightRequest

# there is a valid "feature_flag" in the system
FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID = environ["FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID"]
FEATURE_FLAG_DATA_ID = environ["FEATURE_FLAG_DATA_ID"]

# there is a valid "environment" in the system
ENVIRONMENT_DATA_ID = environ["ENVIRONMENT_DATA_ID"]

body = OverwriteAllocationsRequest(
    data=[
        AllocationDataRequest(
            type=AllocationDataType.ALLOCATIONS,
            attributes=UpsertAllocationRequest(
                key="overwrite-allocation-example-feature-flag",
                name="New targeting rule Example-Feature-Flag",
                targeting_rules=[],
                variant_weights=[
                    VariantWeightRequest(
                        variant_id=FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID,
                        value=100.0,
                    ),
                ],
                exposure_schedule=ExposureScheduleRequest(
                    rollout_options=RolloutOptionsRequest(
                        strategy=RolloutStrategy.UNIFORM_INTERVALS,
                        autostart=False,
                        selection_interval_ms=86400000,
                    ),
                    rollout_steps=[
                        ExposureRolloutStepRequest(
                            exposure_ratio=0.05,
                            interval_ms=None,
                            is_pause_record=False,
                            grouped_step_index=0,
                        ),
                        ExposureRolloutStepRequest(
                            exposure_ratio=0.25,
                            interval_ms=None,
                            is_pause_record=False,
                            grouped_step_index=1,
                        ),
                        ExposureRolloutStepRequest(
                            exposure_ratio=1.0,
                            interval_ms=None,
                            is_pause_record=False,
                            grouped_step_index=2,
                        ),
                    ],
                ),
                guardrail_metrics=[],
                type=AllocationType.CANARY,
            ),
        ),
    ],
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = FeatureFlagsApi(api_client)
    response = api_instance.update_allocations_for_feature_flag_in_environment(
        feature_flag_id=FEATURE_FLAG_DATA_ID, environment_id=ENVIRONMENT_DATA_ID, body=body
    )

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
##### 

```ruby
# Update targeting rules for a flag in an environment returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::FeatureFlagsAPI.new

# there is a valid "feature_flag" in the system
FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID = ENV["FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID"]
FEATURE_FLAG_DATA_ID = ENV["FEATURE_FLAG_DATA_ID"]

# there is a valid "environment" in the system
ENVIRONMENT_DATA_ID = ENV["ENVIRONMENT_DATA_ID"]

body = DatadogAPIClient::V2::OverwriteAllocationsRequest.new({
  data: [
    DatadogAPIClient::V2::AllocationDataRequest.new({
      type: DatadogAPIClient::V2::AllocationDataType::ALLOCATIONS,
      attributes: DatadogAPIClient::V2::UpsertAllocationRequest.new({
        key: "overwrite-allocation-example-feature-flag",
        name: "New targeting rule Example-Feature-Flag",
        targeting_rules: [],
        variant_weights: [
          DatadogAPIClient::V2::VariantWeightRequest.new({
            variant_id: FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID,
            value: 100,
          }),
        ],
        exposure_schedule: DatadogAPIClient::V2::ExposureScheduleRequest.new({
          rollout_options: DatadogAPIClient::V2::RolloutOptionsRequest.new({
            strategy: DatadogAPIClient::V2::RolloutStrategy::UNIFORM_INTERVALS,
            autostart: false,
            selection_interval_ms: 86400000,
          }),
          rollout_steps: [
            DatadogAPIClient::V2::ExposureRolloutStepRequest.new({
              exposure_ratio: 0.05,
              interval_ms: nil,
              is_pause_record: false,
              grouped_step_index: 0,
            }),
            DatadogAPIClient::V2::ExposureRolloutStepRequest.new({
              exposure_ratio: 0.25,
              interval_ms: nil,
              is_pause_record: false,
              grouped_step_index: 1,
            }),
            DatadogAPIClient::V2::ExposureRolloutStepRequest.new({
              exposure_ratio: 1,
              interval_ms: nil,
              is_pause_record: false,
              grouped_step_index: 2,
            }),
          ],
        }),
        guardrail_metrics: [],
        type: DatadogAPIClient::V2::AllocationType::CANARY,
      }),
    }),
  ],
})
p api_instance.update_allocations_for_feature_flag_in_environment(FEATURE_FLAG_DATA_ID, ENVIRONMENT_DATA_ID, body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```rust
// Update targeting rules for a flag in an environment returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_feature_flags::FeatureFlagsAPI;
use datadog_api_client::datadogV2::model::AllocationDataRequest;
use datadog_api_client::datadogV2::model::AllocationDataType;
use datadog_api_client::datadogV2::model::AllocationType;
use datadog_api_client::datadogV2::model::ExposureRolloutStepRequest;
use datadog_api_client::datadogV2::model::ExposureScheduleRequest;
use datadog_api_client::datadogV2::model::OverwriteAllocationsRequest;
use datadog_api_client::datadogV2::model::RolloutOptionsRequest;
use datadog_api_client::datadogV2::model::RolloutStrategy;
use datadog_api_client::datadogV2::model::UpsertAllocationRequest;
use datadog_api_client::datadogV2::model::VariantWeightRequest;

#[tokio::main]
async fn main() {
    // there is a valid "feature_flag" in the system
    let feature_flag_data_attributes_variants_0_id = uuid::Uuid::parse_str(
        &std::env::var("FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID").unwrap(),
    )
    .expect("Invalid UUID");
    let feature_flag_data_id =
        uuid::Uuid::parse_str(&std::env::var("FEATURE_FLAG_DATA_ID").unwrap())
            .expect("Invalid UUID");

    // there is a valid "environment" in the system
    let environment_data_id = uuid::Uuid::parse_str(&std::env::var("ENVIRONMENT_DATA_ID").unwrap())
        .expect("Invalid UUID");
    let body = OverwriteAllocationsRequest::new(vec![AllocationDataRequest::new(
        UpsertAllocationRequest::new(
            "overwrite-allocation-example-feature-flag".to_string(),
            "New targeting rule Example-Feature-Flag".to_string(),
            AllocationType::CANARY,
        )
        .exposure_schedule(ExposureScheduleRequest::new(
            RolloutOptionsRequest::new(RolloutStrategy::UNIFORM_INTERVALS)
                .autostart(Some(false))
                .selection_interval_ms(86400000),
            vec![
                ExposureRolloutStepRequest::new(0.05, 0, false).interval_ms(None),
                ExposureRolloutStepRequest::new(0.25, 1, false).interval_ms(None),
                ExposureRolloutStepRequest::new(1.0, 2, false).interval_ms(None),
            ],
        ))
        .guardrail_metrics(vec![])
        .targeting_rules(vec![])
        .variant_weights(vec![VariantWeightRequest::new(100.0)
            .variant_id(feature_flag_data_attributes_variants_0_id.clone())]),
        AllocationDataType::ALLOCATIONS,
    )]);
    let configuration = datadog::Configuration::new();
    let api = FeatureFlagsAPI::with_config(configuration);
    let resp = api
        .update_allocations_for_feature_flag_in_environment(
            feature_flag_data_id.clone(),
            environment_data_id.clone(),
            body,
        )
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
##### 

```typescript
/**
 * Update targeting rules for a flag in an environment returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v2.FeatureFlagsApi(configuration);

// there is a valid "feature_flag" in the system
const FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID = process.env
  .FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID as string;
const FEATURE_FLAG_DATA_ID = process.env.FEATURE_FLAG_DATA_ID as string;

// there is a valid "environment" in the system
const ENVIRONMENT_DATA_ID = process.env.ENVIRONMENT_DATA_ID as string;

const params: v2.FeatureFlagsApiUpdateAllocationsForFeatureFlagInEnvironmentRequest =
  {
    body: {
      data: [
        {
          type: "allocations",
          attributes: {
            key: "overwrite-allocation-example-feature-flag",
            name: "New targeting rule Example-Feature-Flag",
            targetingRules: [],
            variantWeights: [
              {
                variantId: FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID,
                value: 100,
              },
            ],
            exposureSchedule: {
              rolloutOptions: {
                strategy: "UNIFORM_INTERVALS",
                autostart: false,
                selectionIntervalMs: 86400000,
              },
              rolloutSteps: [
                {
                  exposureRatio: 0.05,
                  intervalMs: undefined,
                  isPauseRecord: false,
                  groupedStepIndex: 0,
                },
                {
                  exposureRatio: 0.25,
                  intervalMs: undefined,
                  isPauseRecord: false,
                  groupedStepIndex: 1,
                },
                {
                  exposureRatio: 1,
                  intervalMs: undefined,
                  isPauseRecord: false,
                  groupedStepIndex: 2,
                },
              ],
            },
            guardrailMetrics: [],
            type: "CANARY",
          },
        },
      ],
    },
    featureFlagId: FEATURE_FLAG_DATA_ID,
    environmentId: ENVIRONMENT_DATA_ID,
  };

apiInstance
  .updateAllocationsForFeatureFlagInEnvironment(params)
  .then((data: v2.ListAllocationsResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"
{% /tab %}
