Create targeting rules for a flag env

POST https://api.ap1.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.ap2.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.datadoghq.eu/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.ddog-gov.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.us2.ddog-gov.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.us3.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://api.us5.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocations

Overview

Creates a new targeting rule (allocation) for a specific feature flag in a specific environment. 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)

Expand All

Field

Type

Description

data [required]

object

Data wrapper for allocation request payloads.

attributes [required]

object

Request to create or update a targeting rule (allocation) for a feature flag environment.

experiment_id

string

The experiment ID for experiment-linked allocations.

exposure_schedule

object

Progressive release request payload.

absolute_start_time

date-time

The absolute UTC start time for this schedule.

control_variant_id

string

The control variant ID used for experiment comparisons.

control_variant_key

string

The control variant key used during creation workflows.

id

uuid

The unique identifier of the progressive rollout.

rollout_options [required]

object

Rollout options request payload.

autostart

boolean

Whether the schedule should begin automatically.

selection_interval_ms

int64

Interval in milliseconds for uniform interval strategies.

strategy [required]

enum

The progression strategy used by a progressive rollout. Allowed enum values: UNIFORM_INTERVALS,NO_ROLLOUT

rollout_steps [required]

[object]

Ordered progression steps for exposure.

exposure_ratio [required]

double

The exposure ratio for this step.

grouped_step_index [required]

int64

Logical index grouping related steps.

id

uuid

The unique identifier of the progression step.

interval_ms

int64

Step duration in milliseconds.

is_pause_record [required]

boolean

Whether this step represents a pause record.

guardrail_metrics

[object]

Guardrail metrics used to monitor and auto-pause or abort.

metric_id [required]

string

The metric ID to monitor.

trigger_action [required]

enum

Action to perform when a guardrail threshold is triggered. Allowed enum values: PAUSE,ABORT

id

uuid

The unique identifier of the targeting rule allocation.

key [required]

string

The unique key of the targeting rule allocation.

name [required]

string

The display name of the targeting rule.

targeting_rules

[object]

Targeting rules that determine audience eligibility.

conditions [required]

[object]

Conditions that must match for this rule.

attribute [required]

string

The user or request attribute to evaluate.

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

value [required]

[string]

Values used by the selected operator.

type [required]

enum

The type of targeting rule (called allocation in the API model). Allowed enum values: FEATURE_GATE,CANARY

variant_weights

[object]

Variant distribution weights.

value [required]

double

The percentage weight for this variant.

variant_id

uuid

The variant ID to assign weight to.

variant_key

string

The variant key to assign weight to.

type [required]

enum

The resource type. Allowed enum values: allocations

{
  "data": {
    "type": "allocations",
    "attributes": {
      "name": "New targeting rule Example-Feature-Flag",
      "key": "new-targeting-rule-example-feature-flag",
      "targeting_rules": [],
      "variant_weights": [
        {
          "variant_id": "550e8400-e29b-41d4-a716-446655440002",
          "value": 100
        }
      ],
      "guardrail_metrics": [],
      "type": "CANARY"
    }
  }
}

Response

Created

Response containing a single targeting rule (allocation).

Expand All

Field

Type

Description

data [required]

object

Data wrapper for targeting rule allocation responses.

attributes [required]

object

Targeting rule (allocation) details for a feature flag environment.

created_at [required]

date-time

The timestamp when the targeting rule allocation was created.

environment_ids [required]

[string]

Environment IDs associated with this targeting rule allocation.

experiment_id

string

The experiment ID linked to this targeting rule allocation.

exposure_schedule

object

Progressive release details for a targeting rule allocation.

absolute_start_time

date-time

The absolute UTC start time for this schedule.

allocation_id [required]

uuid

The targeting rule allocation ID this progressive rollout belongs to.

control_variant_id

string

The control variant ID used for experiment comparisons.

created_at [required]

date-time

The timestamp when the schedule was created.

guardrail_triggered_action

string

Last guardrail action triggered for this schedule.

guardrail_triggers [required]

[object]

Guardrail trigger records for this schedule.

allocation_exposure_schedule_id [required]

uuid

The progressive rollout ID this trigger belongs to.

created_at [required]

date-time

The timestamp when this trigger was created.

flagging_variant_id [required]

uuid

The variant ID that triggered this event.

id [required]

uuid

The unique identifier of the guardrail trigger.

metric_id [required]

string

The metric ID associated with the trigger.

triggered_action [required]

string

The action that was triggered.

updated_at [required]

date-time

The timestamp when this trigger was last updated.

id

uuid

The unique identifier of the progressive rollout.

rollout_options [required]

object

Applied progression options for a progressive rollout.

autostart [required]

boolean

Whether the schedule starts automatically.

selection_interval_ms [required]

int64

Interval in milliseconds for uniform interval strategies.

strategy [required]

enum

The progression strategy used by a progressive rollout. Allowed enum values: UNIFORM_INTERVALS,NO_ROLLOUT

rollout_steps [required]

[object]

Ordered progression steps for exposure.

allocation_exposure_schedule_id [required]

uuid

The progressive rollout ID this step belongs to.

created_at [required]

date-time

The timestamp when the progression step was created.

exposure_ratio [required]

double

The exposure ratio for this step.

grouped_step_index [required]

int64

Logical index grouping related steps.

id [required]

uuid

The unique identifier of the progression step.

interval_ms

int64

Step duration in milliseconds.

is_pause_record [required]

boolean

Whether this step represents a pause record.

order_position [required]

int64

Sort order for the progression step.

updated_at [required]

date-time

The timestamp when the progression step was last updated.

updated_at [required]

date-time

The timestamp when the schedule was last updated.

guardrail_metrics [required]

[object]

Guardrail metrics associated with this targeting rule allocation.

metric_id [required]

string

The metric ID to monitor.

trigger_action [required]

enum

Action to perform when a guardrail threshold is triggered. Allowed enum values: PAUSE,ABORT

triggered_by

string

The signal or system that triggered the action.

id

uuid

The unique identifier of the targeting rule allocation.

key [required]

string

The unique key of the targeting rule allocation.

name [required]

string

The display name of the targeting rule.

order_position [required]

int64

Sort order position within the environment.

targeting_rules [required]

[object]

Conditions associated with this targeting rule allocation.

conditions [required]

[object]

Conditions evaluated by this targeting rule.

attribute [required]

string

The user or request attribute to evaluate.

created_at [required]

date-time

The timestamp when the condition was created.

id [required]

uuid

The unique identifier of the condition.

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

updated_at [required]

date-time

The timestamp when the condition was last updated.

value [required]

[string]

Values used by the selected operator.

created_at [required]

date-time

The timestamp when the targeting rule was created.

id [required]

uuid

The unique identifier of the targeting rule.

updated_at [required]

date-time

The timestamp when the targeting rule was last updated.

type [required]

enum

The type of targeting rule (called allocation in the API model). Allowed enum values: FEATURE_GATE,CANARY

updated_at [required]

date-time

The timestamp when the targeting rule allocation was last updated.

variant_weights [required]

[object]

Weighted variant assignments for this targeting rule allocation.

created_at

date-time

The timestamp when the variant weight was created.

id

uuid

Unique identifier of the variant weight assignment.

updated_at

date-time

The timestamp when the variant weight was last updated.

value [required]

double

The percentage weight for the variant.

variant

object

A variant of a feature flag.

created_at

date-time

The timestamp when the variant was created.

id [required]

uuid

The unique identifier of the variant.

key [required]

string

The unique key of the variant.

name [required]

string

The name of the variant.

updated_at

date-time

The timestamp when the variant was last updated.

value [required]

string

The value of the variant as a string.

variant_id [required]

uuid

The variant ID.

id [required]

uuid

The unique identifier of the targeting rule allocation.

type [required]

enum

The resource type. Allowed enum values: allocations

{
  "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"
  }
}

Accepted - Approval required for this change

Response containing a single targeting rule (allocation).

Expand All

Field

Type

Description

data [required]

object

Data wrapper for targeting rule allocation responses.

attributes [required]

object

Targeting rule (allocation) details for a feature flag environment.

created_at [required]

date-time

The timestamp when the targeting rule allocation was created.

environment_ids [required]

[string]

Environment IDs associated with this targeting rule allocation.

experiment_id

string

The experiment ID linked to this targeting rule allocation.

exposure_schedule

object

Progressive release details for a targeting rule allocation.

absolute_start_time

date-time

The absolute UTC start time for this schedule.

allocation_id [required]

uuid

The targeting rule allocation ID this progressive rollout belongs to.

control_variant_id

string

The control variant ID used for experiment comparisons.

created_at [required]

date-time

The timestamp when the schedule was created.

guardrail_triggered_action

string

Last guardrail action triggered for this schedule.

guardrail_triggers [required]

[object]

Guardrail trigger records for this schedule.

allocation_exposure_schedule_id [required]

uuid

The progressive rollout ID this trigger belongs to.

created_at [required]

date-time

The timestamp when this trigger was created.

flagging_variant_id [required]

uuid

The variant ID that triggered this event.

id [required]

uuid

The unique identifier of the guardrail trigger.

metric_id [required]

string

The metric ID associated with the trigger.

triggered_action [required]

string

The action that was triggered.

updated_at [required]

date-time

The timestamp when this trigger was last updated.

id

uuid

The unique identifier of the progressive rollout.

rollout_options [required]

object

Applied progression options for a progressive rollout.

autostart [required]

boolean

Whether the schedule starts automatically.

selection_interval_ms [required]

int64

Interval in milliseconds for uniform interval strategies.

strategy [required]

enum

The progression strategy used by a progressive rollout. Allowed enum values: UNIFORM_INTERVALS,NO_ROLLOUT

rollout_steps [required]

[object]

Ordered progression steps for exposure.

allocation_exposure_schedule_id [required]

uuid

The progressive rollout ID this step belongs to.

created_at [required]

date-time

The timestamp when the progression step was created.

exposure_ratio [required]

double

The exposure ratio for this step.

grouped_step_index [required]

int64

Logical index grouping related steps.

id [required]

uuid

The unique identifier of the progression step.

interval_ms

int64

Step duration in milliseconds.

is_pause_record [required]

boolean

Whether this step represents a pause record.

order_position [required]

int64

Sort order for the progression step.

updated_at [required]

date-time

The timestamp when the progression step was last updated.

updated_at [required]

date-time

The timestamp when the schedule was last updated.

guardrail_metrics [required]

[object]

Guardrail metrics associated with this targeting rule allocation.

metric_id [required]

string

The metric ID to monitor.

trigger_action [required]

enum

Action to perform when a guardrail threshold is triggered. Allowed enum values: PAUSE,ABORT

triggered_by

string

The signal or system that triggered the action.

id

uuid

The unique identifier of the targeting rule allocation.

key [required]

string

The unique key of the targeting rule allocation.

name [required]

string

The display name of the targeting rule.

order_position [required]

int64

Sort order position within the environment.

targeting_rules [required]

[object]

Conditions associated with this targeting rule allocation.

conditions [required]

[object]

Conditions evaluated by this targeting rule.

attribute [required]

string

The user or request attribute to evaluate.

created_at [required]

date-time

The timestamp when the condition was created.

id [required]

uuid

The unique identifier of the condition.

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

updated_at [required]

date-time

The timestamp when the condition was last updated.

value [required]

[string]

Values used by the selected operator.

created_at [required]

date-time

The timestamp when the targeting rule was created.

id [required]

uuid

The unique identifier of the targeting rule.

updated_at [required]

date-time

The timestamp when the targeting rule was last updated.

type [required]

enum

The type of targeting rule (called allocation in the API model). Allowed enum values: FEATURE_GATE,CANARY

updated_at [required]

date-time

The timestamp when the targeting rule allocation was last updated.

variant_weights [required]

[object]

Weighted variant assignments for this targeting rule allocation.

created_at

date-time

The timestamp when the variant weight was created.

id

uuid

Unique identifier of the variant weight assignment.

updated_at

date-time

The timestamp when the variant weight was last updated.

value [required]

double

The percentage weight for the variant.

variant

object

A variant of a feature flag.

created_at

date-time

The timestamp when the variant was created.

id [required]

uuid

The unique identifier of the variant.

key [required]

string

The unique key of the variant.

name [required]

string

The name of the variant.

updated_at

date-time

The timestamp when the variant was last updated.

value [required]

string

The value of the variant as a string.

variant_id [required]

uuid

The variant ID.

id [required]

uuid

The unique identifier of the targeting rule allocation.

type [required]

enum

The resource type. Allowed enum values: allocations

{
  "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"
  }
}

Bad Request

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Forbidden

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Not Found

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Conflict

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

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 POST "https://api.ap1.datadoghq.com"https://api.ap2.datadoghq.com"https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.us2.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com"https://api.us5.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
// Create allocation for a flag in an environment returns "Created" 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.CreateAllocationsRequest{
		Data: datadogV2.AllocationDataRequest{
			Type: datadogV2.ALLOCATIONDATATYPE_ALLOCATIONS,
			Attributes: datadogV2.UpsertAllocationRequest{
				Name:           "New targeting rule Example-Feature-Flag",
				Key:            "new-targeting-rule-example-feature-flag",
				TargetingRules: []datadogV2.TargetingRuleRequest{},
				VariantWeights: []datadogV2.VariantWeightRequest{
					{
						VariantId: datadog.PtrUUID(FeatureFlagDataAttributesVariants0ID),
						Value:     100,
					},
				},
				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.CreateAllocationsForFeatureFlagInEnvironment(ctx, FeatureFlagDataID, EnvironmentDataID, body)

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

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

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
// Create allocation for a flag in an environment returns "Created" 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.AllocationResponse;
import com.datadog.api.client.v2.model.AllocationType;
import com.datadog.api.client.v2.model.CreateAllocationsRequest;
import com.datadog.api.client.v2.model.UpsertAllocationRequest;
import com.datadog.api.client.v2.model.VariantWeightRequest;
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());
    }

    CreateAllocationsRequest body =
        new CreateAllocationsRequest()
            .data(
                new AllocationDataRequest()
                    .type(AllocationDataType.ALLOCATIONS)
                    .attributes(
                        new UpsertAllocationRequest()
                            .name("New targeting rule Example-Feature-Flag")
                            .key("new-targeting-rule-example-feature-flag")
                            .variantWeights(
                                Collections.singletonList(
                                    new VariantWeightRequest()
                                        .variantId(FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID)
                                        .value(100.0)))
                            .type(AllocationType.CANARY)));

    try {
      AllocationResponse result =
          apiInstance.createAllocationsForFeatureFlagInEnvironment(
              FEATURE_FLAG_DATA_ID, ENVIRONMENT_DATA_ID, body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling FeatureFlagsApi#createAllocationsForFeatureFlagInEnvironment");
      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 and then save the example to Example.java and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
"""
Create allocation for a flag in an environment returns "Created" 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.create_allocations_request import CreateAllocationsRequest
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 = CreateAllocationsRequest(
    data=AllocationDataRequest(
        type=AllocationDataType.ALLOCATIONS,
        attributes=UpsertAllocationRequest(
            name="New targeting rule Example-Feature-Flag",
            key="new-targeting-rule-example-feature-flag",
            targeting_rules=[],
            variant_weights=[
                VariantWeightRequest(
                    variant_id=FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID,
                    value=100.0,
                ),
            ],
            guardrail_metrics=[],
            type=AllocationType.CANARY,
        ),
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = FeatureFlagsApi(api_client)
    response = api_instance.create_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 and then save the example to example.py and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
# Create allocation for a flag in an environment returns "Created" 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::CreateAllocationsRequest.new({
  data: DatadogAPIClient::V2::AllocationDataRequest.new({
    type: DatadogAPIClient::V2::AllocationDataType::ALLOCATIONS,
    attributes: DatadogAPIClient::V2::UpsertAllocationRequest.new({
      name: "New targeting rule Example-Feature-Flag",
      key: "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,
        }),
      ],
      guardrail_metrics: [],
      type: DatadogAPIClient::V2::AllocationType::CANARY,
    }),
  }),
})
p api_instance.create_allocations_for_feature_flag_in_environment(FEATURE_FLAG_DATA_ID, ENVIRONMENT_DATA_ID, body)

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
// Create allocation for a flag in an environment returns "Created" 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::CreateAllocationsRequest;
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 = CreateAllocationsRequest::new(AllocationDataRequest::new(
        UpsertAllocationRequest::new(
            "new-targeting-rule-example-feature-flag".to_string(),
            "New targeting rule Example-Feature-Flag".to_string(),
            AllocationType::CANARY,
        )
        .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
        .create_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 and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
/**
 * Create allocation for a flag in an environment returns "Created" 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.FeatureFlagsApiCreateAllocationsForFeatureFlagInEnvironmentRequest =
  {
    body: {
      data: {
        type: "allocations",
        attributes: {
          name: "New targeting rule Example-Feature-Flag",
          key: "new-targeting-rule-example-feature-flag",
          targetingRules: [],
          variantWeights: [
            {
              variantId: FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID,
              value: 100,
            },
          ],
          guardrailMetrics: [],
          type: "CANARY",
        },
      },
    },
    featureFlagId: FEATURE_FLAG_DATA_ID,
    environmentId: ENVIRONMENT_DATA_ID,
  };

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

Instructions

First install the library and its dependencies and then save the example to example.ts and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"