> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Gestionar feature flags y reglas de rollout

> Cree un feature flag y configure reglas de rollout de entrega segmentada en distintos entornos usando la Automation API.

## Objetivo

Esta guía explica cómo gestionar el ciclo de vida de un feature flag usando la Automation API.

Configure el primer flag completando los siguientes pasos:

1. **Cree un feature flag** usando el [endpoint create a new feature flag](/api-reference/featureflag/create-a-new-feature-flag-configuration).
2. **Añada una regla de rollout** al entorno de desarrollo usando el [endpoint update a feature flag configuration](/api-reference/featureflag/update-a-feature-flag-configuration).
3. **Actualice la regla de rollout** usando el [endpoint update a single rule by ID](/api-reference/featureflag/update-a-single-rule-by-id).

## Requisitos

### Requisitos previos

Antes de usar la Automation API, asegúrese de que dispone de la siguiente información:

#### Token de acceso

La Automation API requiere un [token de acceso](/developer-docs/apis/automation-api-rest/get-started/get-started). Obtenga un token siguiendo las instrucciones de [Obtaining an access token](/developer-docs/apis/automation-api-rest/get-started/get-started#1-obtain-an-access-token).

#### siteCode

Encuentre el `siteCode` navegando a **Admin** > **Projects** en la esquina inferior izquierda.

<Frame>
  ![SiteID](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/api-tutorial/site-id.jpg)
</Frame>

## 1. Crear un feature flag

Cree un feature flag llamado `test_feature_flag_post`, por ejemplo, con la variable `test_variable`.

Como esta solicitud no especifica `environmentConfigurations`, el sistema genera automáticamente las configuraciones para los entornos `development`, `staging` y `production`.

**Endpoint:**

```
POST https://api.kameleoon.com/feature-flags
```

Consulte el [endpoint Create a new feature flag](/api-reference/featureflag/create-a-new-feature-flag-configuration).

**Ejemplo:**

```bash theme={null}
curl -L -X POST 'https://api.kameleoon.com/feature-flags' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
--data-raw '{
  "featureKey": "test_feature_flag_post",
  "name": "test_feature_flag_post",
  "siteCode": "pzllysfw2f",
  "description": "",
  "tags": [],
  "variables": [
    {
      "key": "test_variable",
      "type": "STRING",
      "value": "test"
    }
  ],
  "variations": [
    {
      "name": "On",
      "key": "on",
      "variables": [
        {
          "key": "test_variable",
          "type": "STRING",
          "value": "test"
        }
      ]
    },
    {
      "name": "Off",
      "key": "off",
      "variables": [
        {
          "key": "test_variable",
          "type": "STRING",
          "value": "test"
        }
      ]
    }
  ],
  "attributionWindow": 604800000,
  "archived": false
}
'
```

**Respuesta:**

```json theme={null}
{
  "id": 13134,
  "siteCode": "pzllysfw2f",
  "featureKey": "test_feature_flag_post",
  "name": "test_feature_flag_post",
  "description": "",
  "tags": [],
  "variables": [
    { "key": "test_variable", "type": "STRING", "value": "test" }
  ],
  "variations": [
    {
      "name": "On",
      "key": "on",
      "variables": [
        { "key": "test_variable", "type": "STRING", "value": "test" }
      ]
    },
    {
      "name": "Off",
      "key": "off",
      "variables": [
        { "key": "test_variable", "type": "STRING", "value": "test" }
      ]
    }
  ],
  "secondaryGoalIds": [],
  "attributionWindow": 604800000,
  "health": "HEALTHY",
  "dateCreated": "2025-12-17T10:42:14",
  "dateModified": "2025-12-17T10:42:14",
  "dateContentModified": "2025-12-17T10:42:14",
  "environmentConfigurations": [
    {
      "environmentKey": "production",
      "featureEnabled": false,
      "defaultVariationKey": "off",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    },
    {
      "environmentKey": "staging",
      "featureEnabled": false,
      "defaultVariationKey": "off",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    },
    {
      "environmentKey": "development",
      "featureEnabled": true,
      "defaultVariationKey": "on",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    }
  ],
  "createdById": 34255,
  "archived": false
}
```

## 2. Actualizar el feature flag

Actualice el feature flag para añadir una regla de rollout de tipo `TARGETED_DELIVERY` al entorno `development` con la siguiente configuración:

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/api-tutorial/rollout-rule-1.png)
</Frame>

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/api-tutorial/rollout-rule-2.png)
</Frame>

**Endpoint:**

```
PATCH https://api.kameleoon.com/feature-flags/:siteCode/:featureKey
```

Consulte el [endpoint Update a feature flag configuration](/api-reference/featureflag/update-a-feature-flag-configuration).

**Ejemplo:**

```bash theme={null}
curl -L -X PATCH 'https://api.kameleoon.com/feature-flags/pzllysfw2f/test_feature_flag_post' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
--data-raw '{
  "environmentConfigurations": [
    {
      "environmentKey": "development",
      "featureEnabled": true,
      "defaultVariationKey": "on",
      "rolloutRules": [
        {
          "name": "test rollout rule",
          "type": "TARGETED_DELIVERY",
          "variations": [],
          "trafficAllocations": [
            {
              "variationKey": "on",
              "exposition": 59.0
            }
          ],
          "reallocationTimestamp": null,
          "release": {
            "releaseFrom": "2025-12-11T11:58:01",
            "releaseTo": "2025-12-13T11:58:01",
            "timeZone": "Europe/Paris"
          },
          "state": "ACTIVE",
          "rollbackConditions": [
            {
              "target": "RULE",
              "criteria": "CONVERSION_RATE",
              "comparisonOperator": "GREATER_THAN",
              "matchValue": 20.0,
              "goalId": 400899,
              "visitors": 2,
              "recipients": []
            }
          ],
          "segmentId": 403694,
          "exposition": 59,
          "variationKey": "on"
        }
      ],
      "integrations": {
        "deliveryRules": [],
        "experimentRules": []
      }
    }
  ]
}'
```

**Respuesta:**

```json theme={null}
{
  "id": 13134,
  "siteCode": "pzllysfw2f",
  "featureKey": "test_feature_flag_post",
  "name": "test_feature_flag_post",
  "description": "",
  "tags": [],
  "variables": [
    { "key": "test_variable", "type": "STRING", "value": "test" }
  ],
  "variations": [
    {
      "name": "On",
      "key": "on",
      "variables": [
        { "key": "test_variable", "type": "STRING", "value": "test" }
      ]
    },
    {
      "name": "Off",
      "key": "off",
      "variables": [
        { "key": "test_variable", "type": "STRING", "value": "test" }
      ]
    }
  ],
  "secondaryGoalIds": [],
  "attributionWindow": 604800000,
  "health": "HEALTHY",
  "dateCreated": "2025-12-17T10:42:14",
  "dateModified": "2025-12-17T10:42:14",
  "dateContentModified": "2025-12-17T10:42:14",
  "environmentConfigurations": [
    {
      "environmentKey": "production",
      "featureEnabled": false,
      "defaultVariationKey": "off",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    },
    {
      "environmentKey": "staging",
      "featureEnabled": false,
      "defaultVariationKey": "off",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    },
    {
      "environmentKey": "development",
      "featureEnabled": true,
      "defaultVariationKey": "on",
      "rolloutRules": [
        {
          "id": 20557,
          "name": "test rollout rule",
          "type": "TARGETED_DELIVERY",
          "experimentId": 354972,
          "variations": [],
          "trafficAllocations": [{ "variationKey": "on", "exposition": 59.0 }],
          "reallocationTimestamp": null,
          "release": {
            "releaseFrom": "2025-12-11T11:58:01",
            "releaseTo": "2025-12-13T11:58:01",
            "timeZone": "Europe/Paris"
          },
          "status": "PAUSED",
          "state": "ACTIVE",
          "rollbackConditions": [
            {
              "id": 648,
              "target": "RULE",
              "criteria": "CONVERSION_RATE",
              "comparisonOperator": "GREATER_THAN",
              "matchValue": 20.0,
              "goalId": 400899,
              "visitors": 2,
              "recipients": []
            }
          ],
          "segmentId": 403694,
          "exposition": 59,
          "variationKey": "on"
        }
      ],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    }
  ],
  "createdById": 34255,
  "archived": false
}
```

## 3. Actualizar la regla de rollout

Finalmente, cambie el `matchValue` de `rollbackConditions` a `25` para la regla de rollout con ID `20557`.

**Endpoint:**

```
PATCH https://api.kameleoon.com/feature-flags/rules/:ruleId
```

Consulte el [endpoint Update a feature flag configuration](/api-reference/featureflag/update-a-feature-flag-configuration).

**Ejemplo:**

```bash theme={null}
curl -L -X PATCH 'https://api.kameleoon.com/rules/20557' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
--data-raw '{
  "rollbackConditions": [
    {
      "id": 648,
      "target": "RULE",
      "criteria": "CONVERSION_RATE",
      "comparisonOperator": "GREATER_THAN",
      "matchValue": 25.0,
      "goalId": 400899,
      "visitors": 2,
      "recipients": []
    }
  ]
}'
```

**Respuesta:**

```json theme={null}
{
  "id": 13134,
  "siteCode": "pzllysfw2f",
  "featureKey": "test_feature_flag_post",
  "name": "test_feature_flag_post",
  "description": "",
  "tags": [],
  "variables": [
    { "key": "test_variable", "type": "STRING", "value": "test" }
  ],
  "variations": [
    {
      "name": "On",
      "key": "on",
      "variables": [
        { "key": "test_variable", "type": "STRING", "value": "test" }
      ]
    },
    {
      "name": "Off",
      "key": "off",
      "variables": [
        { "key": "test_variable", "type": "STRING", "value": "test" }
      ]
    }
  ],
  "secondaryGoalIds": [],
  "attributionWindow": 604800000,
  "health": "HEALTHY",
  "dateCreated": "2025-12-17T10:42:14",
  "dateModified": "2025-12-17T10:42:14",
  "dateContentModified": "2025-12-17T10:42:14",
  "environmentConfigurations": [
    {
      "environmentKey": "production",
      "featureEnabled": false,
      "defaultVariationKey": "off",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    },
    {
      "environmentKey": "staging",
      "featureEnabled": false,
      "defaultVariationKey": "off",
      "rolloutRules": [],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    },
    {
      "environmentKey": "development",
      "featureEnabled": true,
      "defaultVariationKey": "on",
      "rolloutRules": [
        {
          "id": 20557,
          "name": "test rollout rule",
          "type": "TARGETED_DELIVERY",
          "experimentId": 354972,
          "variations": [],
          "trafficAllocations": [{ "variationKey": "on", "exposition": 59.0 }],
          "reallocationTimestamp": null,
          "release": {
            "releaseFrom": "2025-12-11T11:58:01",
            "releaseTo": "2025-12-13T11:58:01",
            "timeZone": "Europe/Paris"
          },
          "status": "PAUSED",
          "state": "ACTIVE",
          "rollbackConditions": [
            {
              "id": 648,
              "target": "RULE",
              "criteria": "CONVERSION_RATE",
              "comparisonOperator": "GREATER_THAN",
              "matchValue": 25.0,
              "goalId": 400899,
              "visitors": 2,
              "recipients": []
            }
          ],
          "segmentId": 403694,
          "exposition": 59,
          "variationKey": "on"
        }
      ],
      "integrations": { "deliveryRules": [], "experimentRules": [] },
      "dateModified": "2025-12-17T10:42:14"
    }
  ],
  "createdById": 34255,
  "archived": false
}
```
