For AI agents: A markdown version of this page is available at https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/es/api/latest/feature-flags/add-a-variant-to-a-feature-flag.md. A documentation index is available at /llms.txt.
Language
Datadog site

Add a variant to a feature flag

POSThttps://api.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.us3.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.us5.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.datadoghq.eu/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.ap1.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.ap2.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.uk1.datadoghq.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.ddog-gov.com/api/v2/feature-flags/{feature_flag_id}/variantshttps://api.us2.ddog-gov.com/api/v2/feature-flags/{feature_flag_id}/variants

Descripción general

Adds a single new variant to an existing feature flag. This endpoint is additive-only: it never modifies existing variants. A request whose key already exists on the flag is rejected with 409 Conflict; a value whose type does not match the flag's value_type is rejected with 400. The server generates the variant UUID and returns it in the response body; callers (for example, the flag-migration tool) need this UUID to reference the new variant in subsequent allocation syncs.

This endpoint requires the feature_flag_config_write permission.

OAuth apps require the feature_flag_config_write authorization scope to access this endpoint.

Argumentos

Parámetros de ruta

Nombre
Type
Descripción
feature_flag_id [required]
string

The ID of the feature flag.

Solicitud

Body Data (required)

Campo
Type
Descripción
key [required]
string

The unique key of the variant.

name [required]
string

The name of the variant.

value [required]
string

The value of the variant as a string.

Respuesta

Created

A variant of a feature flag.

Campo
Type
Descripción
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.

Ejemplo de código

Add a variant to a feature flag
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF
# Path parameters
export feature_flag_id="550e8400-e29b-41d4-a716-446655440000"

# 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}/variants" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "key": "dark",
      "name": "Dark Theme",
      "value": "dark"
    },
    "type": "variants"
  }
}
EOF