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

{
  "id": "3t2c8_pokGEeQgeOvRKLT",
  "type": "api-oas-v2",
  "data": {
    "method": "GET",
    "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset",
    "servers": [
      {
        "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset"
      }
    ],
    "name": "Fetch the Ruleset for a Flag in an Environment",
    "description": "Fetch a Ruleset for a Flag in a specific Environment of a project.\n\nThe Ruleset contains the set of all Rules that apply to the Flag for that Environment.\n",
    "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": [],
      "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 retrieval or update of a 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",
            "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
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "pEWGbP_6NWTTCIyrVwXhQ",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request GET \\\n     --url https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/environments/{environment_key}/ruleset \\\n     --header 'accept: application/json'"
        },
        {
          "id": "2Y2bgsBmBeR657fV8HgYS",
          "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: 'GET',\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\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "lEODFV0cYTBTkGaEVbZ20",
          "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\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Get.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "3s0nrBxO631V0Myda-tKw",
          "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\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"GET\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "pEWGbP_6NWTTCIyrVwXhQ"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Successful retrieval or update of a 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"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}