---
title: Enable the Ruleset for a Flag in an Environment
slug: feature-experimentation/api/enable-the-ruleset-for-a-flag-in-an-environment
docTags: 
createdAt: 2026-08-28T15:54:06.731Z
---

{
  "id": "RyTfwXoCN-aGGamT0cMbj",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset/enabled",
    "servers": [
      {
        "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset/enabled"
      }
    ],
    "name": "Enable the Ruleset for a Flag in an Environment",
    "description": "Enables the entire Ruleset for a Flag in an Environment",
    "contentType": "application/json",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "project_id",
          "type": "integer",
          "example": 12345,
          "description": "The project identifier"
        },
        {
          "kind": "required",
          "name": "flag_key",
          "type": "string",
          "example": "recurring_deposit",
          "description": "The Flag identifier"
        },
        {
          "kind": "required",
          "name": "environment_key",
          "type": "string",
          "example": "production",
          "description": "The Environment identifier"
        }
      ],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [],
      "bodyDataParameters": [],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "apiKey",
          "name": "apiKey",
          "kind": "optional",
          "type": "http",
          "scheme": "bearer"
        },
        {
          "id": "OAuth2",
          "name": "OAuth2",
          "kind": "optional",
          "type": "oauth2",
          "description": "Write applications that authenticate with the REST API via OAuth 2.0.",
          "oauth2Flows": {
            "authorizationCode": {
              "authorizationUrl": "https://app.optimizely.com/oauth2/authorize",
              "tokenUrl": "https://app.optimizely.com/oauth2/token",
              "scopes": {
                "all": "Grants all access"
              }
            }
          },
          "requiredScopes": [
            "read",
            "write"
          ]
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "<p>Successful enabling of the Ruleset.</p>\n<p>The response includes RESTful JSON (<a href=\"https://restfuljson.org/\" target=\"_blank\">https://restfuljson.org/</a>) styled links. If a\nlink is not present in the response, it indicates a user is not authorized to access\nthe related resource.</p>",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "example": "{\"archived\":false,\"default_variation_key\":false,\"default_variation_name\":false,\"disable_url\":\"...\",\"enable_url\":\"...\",\"enabled\":true,\"environment_key\":\"development\",\"environment_name\":\"Development\",\"fetch_default_variation_url\":\"...\",\"fetch_flag_url\":\"...\",\"flag_key\":\"recurring_deposit\",\"id\":23456746,\"rule_priorities\":[\"landing_page_callout\",\"paid_users\"],\"rules\":{\"landing_page_callout\":{\"allow_list\":{\"xyz123\":{\"user_id\":\"xyz123\",\"variation\":{\"key\":false,\"name\":false}}},\"archived\":false,\"audience_conditions\":[\"or\",{\"audience_id\":222222}],\"audience_ids\":[5340810295],\"created_time\":\"2021-02-03T19:57:31.357168+00:00\",\"description\":\"\",\"distribution_mode\":\"stats_accelerator\",\"enabled\":true,\"id\":1,\"key\":\"landing_page_callout\",\"layer_experiment_id\\\"\":9000000010002,\"layer_id\\\"\":9000000010002,\"metrics\":[{\"aggregator\":\"sum\",\"display_title\":\"Increasing Revenue by Session\",\"event_id\":33333333,\"event_type\":\"custom\",\"field\":\"revenue\",\"scope\":\"session\",\"winning_direction\":\"increasing\"}],\"name\":\"Landing Page Callout\",\"percentage_included\":5000,\"type\":\"a/b\",\"updated_time\":\"2021-02-03T19:57:31.357173+00:00\",\"urn\":\"rules.flags.optimizely.com::1\",\"variations\":{\"false\":{\"key\":false,\"name\":false,\"percentage_included\":5000},\"true\":{\"key\":true,\"name\":true,\"percentage_included\":5000}}},\"paid_users\":{\"allow_list\":{\"xyz123\":{\"user_id\":\"xyz123\",\"variation\":{\"key\":false,\"name\":false}}},\"archived\":false,\"audience_conditions\":[\"or\",{\"audience_id\":123456}],\"audience_ids\":[123456],\"created_time\":\"2021-02-03T19:57:31.366368+00:00\",\"description\":\"\",\"enabled\":true,\"id\":2,\"key\":\"paid_users\",\"layer_experiment_id\\\"\":9000000010003,\"layer_id\\\"\":9000000010003,\"metrics\":[],\"name\":\"Paid Users\",\"percentage_included\":10000,\"type\":\"targeted_delivery\",\"updated_time\":\"2021-02-03T19:57:31.366372+00:00\",\"urn\":\"rules.flags.optimizely.com::2\",\"variations\":{\"true\":{\"key\":true,\"name\":true,\"percentage_included\":10000}}}},\"update_url\":\"...\",\"updated_time\":\"2019-05-08T00:00:00+00:00\",\"url\":\"...\",\"urn\":\"rulesets.flags.optimizely.com::23456746\"}",
            "description": "Rules configuration specific to an environment.",
            "customType": "Ruleset",
            "schema": [
              {
                "name": "archived",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "Whether this Ruleset is archived or not. The ruleset is archived if the Flag was archived.",
                "example": false
              },
              {
                "name": "default_variation_key",
                "kind": "optional",
                "type": "string",
                "description": "<p>User-facing Unique identifier of the Variation.</p>",
                "example": "high_discount"
              },
              {
                "name": "default_variation_name",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "description": "User friendly identifer of the Variation.",
                "example": "High Discount"
              },
              {
                "name": "disable_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "",
                "complexType": "oneOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "enable_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "",
                "complexType": "oneOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "enabled",
                "kind": "optional",
                "type": "boolean",
                "description": "Indicates if the rule is enabled or not in an environment.",
                "default": false
              },
              {
                "name": "environment_id",
                "kind": "optional",
                "type": "number",
                "description": "Environment id."
              },
              {
                "name": "environment_key",
                "kind": "required",
                "type": "string",
                "description": "<p>User-facing Environment identifier.</p>",
                "example": "production"
              },
              {
                "name": "environment_name",
                "kind": "optional",
                "type": "string",
                "description": "Environment name.",
                "example": "Production"
              },
              {
                "name": "fetch_default_variation_url",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "description": "A url to the variation that will be executed if no rule audience is served."
              },
              {
                "name": "fetch_flag_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "A url to fetch the Flag used by this Ruleset.",
                "complexType": "oneOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "flag_key",
                "kind": "required",
                "type": "string",
                "description": "<p>User-facing Unique identifier of the Flag.</p>",
                "example": "recurring_deposit"
              },
              {
                "name": "id",
                "kind": "optional",
                "type": "integer",
                "readOnly": true,
                "description": "",
                "example": 23456746
              },
              {
                "name": "revision",
                "kind": "optional",
                "type": "integer",
                "readOnly": true,
                "description": "Revision number for tracking changes"
              },
              {
                "name": "role",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "description": "Granular permission role",
                "example": "admin"
              },
              {
                "name": "rule_priorities",
                "kind": "required",
                "type": "array",
                "description": "Ordered array of rule keys for the set.",
                "example": "[\"new_users\",\"paid_users\",\"trial_users\"]",
                "itemType": "string",
                "customType": "string[]",
                "itemExample": "",
                "itemDefault": ""
              },
              {
                "name": "rules",
                "kind": "optional",
                "type": "object",
                "description": "",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "RuleMap",
                    "description": "",
                    "modelRef": "#/components/schemas/RuleMap",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "status",
                "kind": "optional",
                "type": "string<draft | running | paused>",
                "description": "status of ruleset.",
                "enum": [
                  "draft",
                  "running",
                  "paused"
                ]
              },
              {
                "name": "update_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "",
                "complexType": "oneOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "updated_time",
                "kind": "optional",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "Timestamp when the Ruleset was last updated",
                "example": "2019-05-08T00:00:00.000Z",
                "format": "date-time"
              },
              {
                "name": "url",
                "kind": "required",
                "type": "object",
                "readOnly": true,
                "description": "Link to self",
                "complexType": "oneOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "urn",
                "kind": "required",
                "type": "string",
                "readOnly": true,
                "description": "The URN for the Ruleset",
                "example": "ruleset.flag.optimizely.com::a308d9ae-89ba-11ea-bc55-0242ac130003"
              }
            ],
            "modelRef": "#/components/schemas/Ruleset",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Malformed requests and invalid parameter names and types",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "Invalid credentials",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "403",
        "description": "Do not have permission to perform the operation",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "404",
        "description": "Not found. No content",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "409",
        "description": "<p>The change is gated by an active change-approval policy (or flag scheduling was unavailable to verify it); submit it through flag scheduling as a change request.</p>",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "YQa9cmHyCKm_3mQ1dR8y-",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset/enabled \\\n     --header 'accept: application/json'"
        },
        {
          "id": "ZqAURZ1e-04o3ibWOyITB",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset/enabled\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "U4thk2HYZs7HNzocxplDW",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset/enabled\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "LojzcYkNaVNgmuiSyXFIk",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset/enabled\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "YQa9cmHyCKm_3mQ1dR8y-"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Successful enabling of the Ruleset.\nThe response includes RESTful JSON (https://restfuljson.org/) styled links. If a\nlink is not present in the response, it indicates a user is not authorized to access\nthe related resource.\n{\n  \"archived\": false,\n  \"default_variation_key\": \"high_discount\",\n  \"default_variation_name\": \"High Discount\",\n  \"disable_url\": {},\n  \"enable_url\": {},\n  \"enabled\": false,\n  \"environment_id\": 0,\n  \"environment_key\": \"production\",\n  \"environment_name\": \"Production\",\n  \"fetch_default_variation_url\": \"\",\n  \"fetch_flag_url\": {},\n  \"flag_key\": \"recurring_deposit\",\n  \"id\": 23456746,\n  \"revision\": 0,\n  \"role\": \"admin\",\n  \"rule_priorities\": [\n    \"\"\n  ],\n  \"rules\": {},\n  \"status\": \"\",\n  \"update_url\": {},\n  \"updated_time\": \"2019-05-08T00:00:00.000Z\",\n  \"url\": {},\n  \"urn\": \"ruleset.flag.optimizely.com::a308d9ae-89ba-11ea-bc55-0242ac130003\"\n}"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Malformed requests and invalid parameter names and types\n"
        },
        {
          "id": "response-2-401",
          "language": "401",
          "code": "// Invalid credentials\n"
        },
        {
          "id": "response-3-403",
          "language": "403",
          "code": "// Do not have permission to perform the operation\n"
        },
        {
          "id": "response-4-404",
          "language": "404",
          "code": "// Not found. No content\n"
        },
        {
          "id": "response-5-409",
          "language": "409",
          "code": "// The change is gated by an active change-approval policy (or flag scheduling was unavailable to verify it); submit it through flag scheduling as a change request.\n"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}