Create targeting rules for a flag env
https://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}/allocationshttps://api.datadoghq.eu/api/v2/feature-flags/{feature_flag_id}/environments/{environment_id}/allocationshttps://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.uk1.datadoghq.com/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}/allocationsOverview
Creates a new targeting rule (allocation) for a specific feature flag in a specific environment.
OAuth apps require the feature_flag_config_write authorization scope to access this endpoint.
Arguments
Path Parameters
feature_flag_id [required]The ID of the feature flag.
environment_id [required]The ID of the environment.
Request
Body Data (required)
data [required]Data wrapper for allocation request payloads.
attributes [required]Request to create or update a targeting rule (allocation) for a feature flag environment.
experiment_idThe experiment ID for experiment-linked allocations.
exposure_scheduleProgressive release request payload.
absolute_start_timeThe absolute UTC start time for this schedule.
control_variant_idThe control variant ID used for experiment comparisons.
control_variant_keyThe control variant key used during creation workflows.
idThe unique identifier of the progressive rollout.
rollout_options [required]Rollout options request payload.
autostartWhether the schedule should begin automatically.
selection_interval_msInterval in milliseconds for uniform interval strategies.
strategy [required]The progression strategy used by a progressive rollout.
UNIFORM_INTERVALS, NO_ROLLOUTrollout_steps [required]Ordered progression steps for exposure.
exposure_ratio [required]The exposure ratio for this step.
grouped_step_index [required]Logical index grouping related steps.
idThe unique identifier of the progression step.
interval_msStep duration in milliseconds.
is_pause_record [required]Whether this step represents a pause record.
guardrail_metricsGuardrail metrics used to monitor and auto-pause or abort.
metric_id [required]The metric ID to monitor.
trigger_action [required]Action to perform when a guardrail threshold is triggered.
PAUSE, ABORTidThe unique identifier of the targeting rule allocation.
key [required]The unique key of the targeting rule allocation.
name [required]The display name of the targeting rule.
targeting_rulesTargeting rules that determine audience eligibility.
conditions [required]Conditions that must match for this rule.
attributeThe user or request attribute to evaluate. Required for inline conditions; omit when saved_filter_id is set.
operatorThe operator used in a targeting condition.
LT, LTE, GT, GTE, MATCHES, NOT_MATCHES, ONE_OF, NOT_ONE_OF, IS_NULL, EQUALSsaved_filter_idThe ID of a saved filter to reference as this condition. Mutually exclusive
with operator, attribute, and value. When set, the saved filter's
targeting rules are evaluated in place of an inline predicate.
valueValues used by the selected operator. Required for inline conditions; omit when saved_filter_id is set.
type [required]The type of targeting rule (called allocation in the API model).
FEATURE_GATE, CANARYvariant_weightsVariant distribution weights.
value [required]The percentage weight for this variant.
variant_idThe variant ID to assign weight to.
variant_keyThe variant key to assign weight to.
type [required]The resource type.
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).
data [required]Data wrapper for targeting rule allocation responses.
attributes [required]Targeting rule (allocation) details for a feature flag environment.
created_at [required]The timestamp when the targeting rule allocation was created.
environment_ids [required]Environment IDs associated with this targeting rule allocation.
experiment_idThe experiment ID linked to this targeting rule allocation.
exposure_scheduleProgressive release details for a targeting rule allocation.
absolute_start_timeThe absolute UTC start time for this schedule.
allocation_id [required]The targeting rule allocation ID this progressive rollout belongs to.
control_variant_idThe control variant ID used for experiment comparisons.
created_at [required]The timestamp when the schedule was created.
guardrail_triggered_actionLast guardrail action triggered for this schedule.
guardrail_triggers [required]Guardrail trigger records for this schedule.
allocation_exposure_schedule_id [required]The progressive rollout ID this trigger belongs to.
created_at [required]The timestamp when this trigger was created.
flagging_variant_id [required]The variant ID that triggered this event.
id [required]The unique identifier of the guardrail trigger.
metric_id [required]The metric ID associated with the trigger.
triggered_action [required]The action that was triggered.
updated_at [required]The timestamp when this trigger was last updated.
idThe unique identifier of the progressive rollout.
rollout_options [required]Applied progression options for a progressive rollout.
autostart [required]Whether the schedule starts automatically.
selection_interval_ms [required]Interval in milliseconds for uniform interval strategies.
strategy [required]The progression strategy used by a progressive rollout.
UNIFORM_INTERVALS, NO_ROLLOUTrollout_steps [required]Ordered progression steps for exposure.
allocation_exposure_schedule_id [required]The progressive rollout ID this step belongs to.
created_at [required]The timestamp when the progression step was created.
exposure_ratio [required]The exposure ratio for this step.
grouped_step_index [required]Logical index grouping related steps.
id [required]The unique identifier of the progression step.
interval_msStep duration in milliseconds.
is_pause_record [required]Whether this step represents a pause record.
order_position [required]Sort order for the progression step.
updated_at [required]The timestamp when the progression step was last updated.
updated_at [required]The timestamp when the schedule was last updated.
guardrail_metrics [required]Guardrail metrics associated with this targeting rule allocation.
metric_id [required]The metric ID to monitor.
trigger_action [required]Action to perform when a guardrail threshold is triggered.
PAUSE, ABORTtriggered_byThe signal or system that triggered the action.
idThe unique identifier of the targeting rule allocation.
key [required]The unique key of the targeting rule allocation.
name [required]The display name of the targeting rule.
order_position [required]Sort order position within the environment.
targeting_rules [required]Conditions associated with this targeting rule allocation.
conditions [required]Conditions evaluated by this targeting rule.
attributeThe user or request attribute to evaluate. Omitted for saved-filter references.
created_at [required]The timestamp when the condition was created.
id [required]The unique identifier of the condition.
operatorThe operator used in a targeting condition.
LT, LTE, GT, GTE, MATCHES, NOT_MATCHES, ONE_OF, NOT_ONE_OF, IS_NULL, EQUALSsaved_filter_idThe ID of the saved filter referenced by this condition, or null for inline conditions.
updated_at [required]The timestamp when the condition was last updated.
valueValues used by the selected operator. Omitted for saved-filter references.
created_at [required]The timestamp when the targeting rule was created.
id [required]The unique identifier of the targeting rule.
updated_at [required]The timestamp when the targeting rule was last updated.
type [required]The type of targeting rule (called allocation in the API model).
FEATURE_GATE, CANARYupdated_at [required]The timestamp when the targeting rule allocation was last updated.
variant_weights [required]Weighted variant assignments for this targeting rule allocation.
created_atThe timestamp when the variant weight was created.
idUnique identifier of the variant weight assignment.
updated_atThe timestamp when the variant weight was last updated.
value [required]The percentage weight for the variant.
variantA variant of a feature flag.
created_atThe timestamp when the variant was created.
id [required]The unique identifier of the variant.
key [required]The unique key of the variant.
name [required]The name of the variant.
updated_atThe timestamp when the variant was last updated.
value [required]The value of the variant as a string.
variant_id [required]The variant ID.
id [required]The unique identifier of the targeting rule allocation.
type [required]The resource type.
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",
"saved_filter_id": "550e8400-e29b-41d4-a716-446655440090",
"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).
data [required]Data wrapper for targeting rule allocation responses.
attributes [required]Targeting rule (allocation) details for a feature flag environment.
created_at [required]The timestamp when the targeting rule allocation was created.
environment_ids [required]Environment IDs associated with this targeting rule allocation.
experiment_idThe experiment ID linked to this targeting rule allocation.
exposure_scheduleProgressive release details for a targeting rule allocation.
absolute_start_timeThe absolute UTC start time for this schedule.
allocation_id [required]The targeting rule allocation ID this progressive rollout belongs to.
control_variant_idThe control variant ID used for experiment comparisons.
created_at [required]The timestamp when the schedule was created.
guardrail_triggered_actionLast guardrail action triggered for this schedule.
guardrail_triggers [required]Guardrail trigger records for this schedule.
allocation_exposure_schedule_id [required]The progressive rollout ID this trigger belongs to.
created_at [required]The timestamp when this trigger was created.
flagging_variant_id [required]The variant ID that triggered this event.
id [required]The unique identifier of the guardrail trigger.
metric_id [required]The metric ID associated with the trigger.
triggered_action [required]The action that was triggered.
updated_at [required]The timestamp when this trigger was last updated.
idThe unique identifier of the progressive rollout.
rollout_options [required]Applied progression options for a progressive rollout.
autostart [required]Whether the schedule starts automatically.
selection_interval_ms [required]Interval in milliseconds for uniform interval strategies.
strategy [required]The progression strategy used by a progressive rollout.
UNIFORM_INTERVALS, NO_ROLLOUTrollout_steps [required]Ordered progression steps for exposure.
allocation_exposure_schedule_id [required]The progressive rollout ID this step belongs to.
created_at [required]The timestamp when the progression step was created.
exposure_ratio [required]The exposure ratio for this step.
grouped_step_index [required]Logical index grouping related steps.
id [required]The unique identifier of the progression step.
interval_msStep duration in milliseconds.
is_pause_record [required]Whether this step represents a pause record.
order_position [required]Sort order for the progression step.
updated_at [required]The timestamp when the progression step was last updated.
updated_at [required]The timestamp when the schedule was last updated.
guardrail_metrics [required]Guardrail metrics associated with this targeting rule allocation.
metric_id [required]The metric ID to monitor.
trigger_action [required]Action to perform when a guardrail threshold is triggered.
PAUSE, ABORTtriggered_byThe signal or system that triggered the action.
idThe unique identifier of the targeting rule allocation.
key [required]The unique key of the targeting rule allocation.
name [required]The display name of the targeting rule.
order_position [required]Sort order position within the environment.
targeting_rules [required]Conditions associated with this targeting rule allocation.
conditions [required]Conditions evaluated by this targeting rule.
attributeThe user or request attribute to evaluate. Omitted for saved-filter references.
created_at [required]The timestamp when the condition was created.
id [required]The unique identifier of the condition.
operatorThe operator used in a targeting condition.
LT, LTE, GT, GTE, MATCHES, NOT_MATCHES, ONE_OF, NOT_ONE_OF, IS_NULL, EQUALSsaved_filter_idThe ID of the saved filter referenced by this condition, or null for inline conditions.
updated_at [required]The timestamp when the condition was last updated.
valueValues used by the selected operator. Omitted for saved-filter references.
created_at [required]The timestamp when the targeting rule was created.
id [required]The unique identifier of the targeting rule.
updated_at [required]The timestamp when the targeting rule was last updated.
type [required]The type of targeting rule (called allocation in the API model).
FEATURE_GATE, CANARYupdated_at [required]The timestamp when the targeting rule allocation was last updated.
variant_weights [required]Weighted variant assignments for this targeting rule allocation.
created_atThe timestamp when the variant weight was created.
idUnique identifier of the variant weight assignment.
updated_atThe timestamp when the variant weight was last updated.
value [required]The percentage weight for the variant.
variantA variant of a feature flag.
created_atThe timestamp when the variant was created.
id [required]The unique identifier of the variant.
key [required]The unique key of the variant.
name [required]The name of the variant.
updated_atThe timestamp when the variant was last updated.
value [required]The value of the variant as a string.
variant_id [required]The variant ID.
id [required]The unique identifier of the targeting rule allocation.
type [required]The resource type.
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",
"saved_filter_id": "550e8400-e29b-41d4-a716-446655440090",
"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.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Forbidden
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Not Found
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Conflict
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Code Example
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
EOF# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"
export environment_id="550e8400-e29b-41d4-a716-446655440001"
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/feature-flags/${feature_flag_id}/environments/${environment_id}/allocations" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"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"
}
}
}
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())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" 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();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" 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()
configuration.access_token = environ["DD_BEARER_TOKEN"]
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"# Create allocation for a flag in an environment returns "Created" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
end
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" 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.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us3.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us5.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="datadoghq.eu" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ap1.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ap2.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="uk1.datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo runDD_SITE="us2.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({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
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.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"