Passer au contenu principal

Objectif

Ce guide explique comment gérer le cycle de vie d’un feature flag à l’aide de l’Automation API. Configurez le premier flag en suivant les étapes ci-dessous :
  1. Créer un feature flag en utilisant l’endpoint create a new feature flag.
  2. Ajouter une règle de rollout à l’environnement de développement en utilisant l’endpoint update a feature flag configuration.
  3. Mettre à jour la règle de rollout en utilisant l’endpoint update a single rule by ID.

Prérequis

Conditions préalables

Avant d’utiliser l’Automation API, assurez-vous d’avoir les informations suivantes :

Access token

L’Automation API nécessite un access token. Obtenez un token en suivant les instructions de Obtenir un access token.

siteCode

Trouvez le siteCode en accédant à Admin > Projets dans le coin inférieur gauche.
SiteID

1. Créer un feature flag

Créez un feature flag appelé test_feature_flag_post, par exemple, avec la variable test_variable. Comme cette requête ne spécifie pas d’environmentConfigurations, le système génère automatiquement des configurations pour les environnements development, staging et production. Endpoint :
POST https://api.kameleoon.com/feature-flags
Voir l’endpoint Create a new feature flag. Exemple :
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
}
'
Réponse :
{
  "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. Mettre à jour le feature flag

Mettez à jour le feature flag pour ajouter une règle de rollout TARGETED_DELIVERY à l’environnement development avec la configuration suivante :
Endpoint :
PATCH https://api.kameleoon.com/feature-flags/:siteCode/:featureKey
Voir l’endpoint Update a feature flag configuration. Exemple :
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": []
      }
    }
  ]
}'
Réponse :
{
  "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. Mettre à jour la règle de rollout

Enfin, changez la matchValue des rollbackConditions à 25 pour la règle de rollout ID 20557. Endpoint :
PATCH https://api.kameleoon.com/feature-flags/rules/:ruleId
Voir l’endpoint Update a feature flag configuration. Exemple :
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": []
    }
  ]
}'
Réponse :
{
  "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
}