---
title: Fetch all variable definitions for flag.
slug: feature-experimentation/api/fetch-all-variable-definitions-for-flag
docTags: 
createdAt: 2026-08-28T15:54:06.731Z
---

{
  "id": "iOBjtjRiaOfJahu1DmcbK",
  "type": "api-oas-v2",
  "data": {
    "method": "GET",
    "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variable_definitions",
    "servers": [
      {
        "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variable_definitions"
      }
    ],
    "name": "Fetch all variable definitions for flag.",
    "description": "",
    "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"
        }
      ],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [
        {
          "kind": "optional",
          "name": "per_page",
          "type": "integer<int64>",
          "description": "The max number of items to include per page or results.",
          "format": "int64"
        },
        {
          "kind": "optional",
          "name": "page_number",
          "type": "integer<int64>",
          "description": "<p>Bypass page_token to jump to specific page</p>",
          "format": "int64"
        },
        {
          "kind": "optional",
          "name": "page_token",
          "type": "string",
          "description": "<p>Pagination page token. Implements prev, next, last, first</p>"
        },
        {
          "kind": "optional",
          "name": "page_window",
          "type": "integer",
          "description": "<p>Number of previous and next page links to supply for the request (defaults to 1).</p>"
        },
        {
          "kind": "optional",
          "name": "sort",
          "type": "array",
          "description": "Sort the Variable Definitions based on the attributes from left to right.\n",
          "schema": [],
          "itemType": "string",
          "customType": "string[]"
        }
      ],
      "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 of a page of Variable Definitions for a Flag.</p>\n<p>The response includes RESTful JSON (<a href=\"https://restfuljson.org/\" target=\"_blank\">https://restfuljson.org/</a>) styled links and pagination metadata.\nObjects in this API MAY include a url property for a link to itself and MAY append _url to properties for related links.\nIf a link is not present in the response, it indicates a user is not authorized to access the related resource.</p>",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "VariableDefinitions",
            "schema": [
              {
                "name": "count",
                "kind": "optional",
                "type": "integer",
                "description": "Number of Variables on the current page.",
                "example": 1
              },
              {
                "name": "first_url",
                "kind": "optional",
                "type": "object",
                "description": "Link to first page of Variables in a series.",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "items",
                "kind": "optional",
                "type": "array",
                "description": "",
                "modelRef": "#/components/schemas/VariableDefinition",
                "customType": "VariableDefinition[]",
                "schema": [
                  {
                    "name": "default_value",
                    "kind": "required",
                    "type": "string",
                    "description": "The default value for the Flag Variable Definition",
                    "example": "0.0"
                  },
                  {
                    "name": "description",
                    "kind": "optional",
                    "type": "string",
                    "description": "Additional context of the Flag Variable Definition",
                    "example": "This variable is used to configure the amount used for computing the discount"
                  },
                  {
                    "name": "key",
                    "kind": "required",
                    "type": "string",
                    "description": "Unique string identifier for the Flag Variable Definition within the Flag",
                    "example": "amount"
                  },
                  {
                    "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": "type",
                    "kind": "required",
                    "type": "string<boolean | string | double | integer | json>",
                    "description": "The datatype for the Flag Variable Definition",
                    "example": "double",
                    "enum": [
                      "boolean",
                      "string",
                      "double",
                      "integer",
                      "json"
                    ]
                  }
                ]
              },
              {
                "name": "last_url",
                "kind": "optional",
                "type": "object",
                "description": "Link to the last page of Variables in a series.",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "next_url",
                "kind": "optional",
                "type": "object",
                "description": "<p>List of links to next pages of Variables in a series.</p>\n<p>The first element in the array is the exact next page after the current record, etc.</p>",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlList",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlList",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "page",
                "kind": "optional",
                "type": "integer",
                "description": "<p>Number of the current page. 1-index based.</p>",
                "example": 1
              },
              {
                "name": "prev_url",
                "kind": "optional",
                "type": "object",
                "description": "<p>List of links to previous pages of Variables in a series.</p>\n<p>The first element in the array is the exact previous page before the current record, etc.</p>",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlList",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlList",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "total_count",
                "kind": "optional",
                "type": "integer",
                "description": "Total number of Variables for this series.",
                "example": 1
              },
              {
                "name": "total_pages",
                "kind": "optional",
                "type": "integer",
                "description": "Total number of pages for this series.",
                "example": 1
              }
            ],
            "modelRef": "#/components/schemas/VariableDefinitions",
            "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
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "qD0MD7lv2wTbjKXqNsyko",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request GET \\\n     --url https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variable_definitions \\\n     --header 'accept: application/json'"
        },
        {
          "id": "jPmF7E1WtgLEg5ZOEjvgu",
          "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}/variable_definitions\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "j1gHF56ByunS0DdLPo-cI",
          "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}/variable_definitions\")\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": "jO9ArxbrvsjNNqYJAhUL1",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variable_definitions\"\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": "qD0MD7lv2wTbjKXqNsyko"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Successful retrieval of a page of Variable Definitions for a Flag.\nThe response includes RESTful JSON (https://restfuljson.org/) styled links and pagination metadata.\nObjects in this API MAY include a url property for a link to itself and MAY append _url to properties for related links.\nIf a link is not present in the response, it indicates a user is not authorized to access the related resource.\n{\n  \"count\": 1,\n  \"first_url\": {},\n  \"items\": [\n    {\n      \"default_value\": \"0.0\",\n      \"description\": \"This variable is used to configure the amount used for computing the discount\",\n      \"key\": \"amount\",\n      \"revision\": 0,\n      \"role\": \"admin\",\n      \"type\": \"double\"\n    }\n  ],\n  \"last_url\": {},\n  \"next_url\": {},\n  \"page\": 1,\n  \"prev_url\": {},\n  \"total_count\": 1,\n  \"total_pages\": 1\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"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}