---
title: Create a New Variation
slug: feature-experimentation/api/create-a-new-variation
createdAt: 2026-08-28T15:54:06.731Z
---

{
  "id": "2RmQMAhU2L8boPrjViZ6d",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variations",
    "servers": [
      {
        "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variations"
      }
    ],
    "name": "Create a New Variation",
    "description": "<p>Creates a new Variation for a specific Flag in a project.</p>\n<p>This operation corresponds to the <code>create_url</code> in a Variations response.</p>\n<p>Required properties must be present in the request body.</p>",
    "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": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "",
          "customType": "VariationRequestBody",
          "schema": [
            {
              "name": "description",
              "kind": "optional",
              "type": "string",
              "description": "Additional context of the Variation",
              "example": "Use this to provide high discounts"
            },
            {
              "name": "key",
              "kind": "required",
              "type": "string",
              "description": "<p>User-facing Unique identifier of the Variation</p>",
              "example": "high_discount"
            },
            {
              "name": "name",
              "kind": "required",
              "type": "string",
              "description": "<p>User-facing name of the Variation</p>",
              "example": "High Discount"
            },
            {
              "name": "screenshot_name",
              "kind": "optional",
              "type": "string",
              "nullable": true,
              "description": "Original filename of the uploaded screenshot image. Null when no screenshot has been attached.",
              "example": "hero-banner.png",
              "maxLength": 255
            },
            {
              "name": "screenshot_url",
              "kind": "optional",
              "type": "string",
              "nullable": true,
              "description": "<p>Backend proxy path to the variation's uploaded screenshot image. Null when no screenshot has been attached. Format: /projects/{project_id}/files/{file_id}</p>",
              "example": "/projects/123/files/a1b2c3d4-e5f6-7890-abcd-ef1234567890",
              "maxLength": 2000
            },
            {
              "name": "variables",
              "kind": "optional",
              "type": "map",
              "description": "Map of flag variables that include variable key and value",
              "example": "{\"advanced\":{\"value\":\"{\\n\\t\\\"hello\\\": 123\\n}\"},\"amount\":{\"value\":\"10.0\"},\"message\":{\"value\":\"Enjoy!!\"}}",
              "customType": "map<string, VariableValue>",
              "schema": []
            }
          ],
          "modelRef": "#/components/schemas/VariationRequestBody",
          "isExpanded": true
        }
      ],
      "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": "201",
        "description": "<p>Successful retrieval, creation or update of a Variation for a Flag.</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": "{\"archive_url\":\"...\",\"archived\":false,\"created_time\":\"2019-05-08T00:00:00.000Z\",\"delete_url\":\"...\",\"description\":\"Use this to provide high discounts\",\"enabled\":true,\"environment_usage_count\":{\"development\":2,\"production\":3},\"fetch_flag_url\":\"...\",\"flag_key\":\"recurring_deposit\",\"id\":45633995,\"key\":\"high_discount\",\"name\":\"High Discount\",\"revision\":1,\"unarchive_url\":\"...\",\"update_url\":\"...\",\"updated_time\":\"2019-05-08T00:00:00.000Z\",\"url\":\"...\",\"urn\":\"variations.flag.optimizely.com::45633995\",\"variables\":{\"advanced\":{\"key\":\"advanced\",\"type\":\"json\",\"value\":\"{\\n\\t\\\"hello\\\": 123\\n}\"},\"amount\":{\"key\":\"amount\",\"type\":\"double\",\"value\":\"10.0\"},\"message\":{\"key\":\"message\",\"type\":\"string\",\"value\":\"Enjoy!!\"}}}",
            "description": "",
            "customType": "Variation",
            "schema": [
              {
                "name": "archive_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "Link to archive this Variation",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "archived",
                "kind": "optional",
                "type": "boolean",
                "description": "Indicates if the Variation is archived or not"
              },
              {
                "name": "created_time",
                "kind": "required",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "Timestamp when the Variation is created",
                "format": "date-time"
              },
              {
                "name": "delete_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "Link to delete this Variation",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "description",
                "kind": "optional",
                "type": "string",
                "description": "Additional context of the Variation"
              },
              {
                "name": "enabled",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "Indicates if the Variation is enabled or not"
              },
              {
                "name": "environment_usage_count",
                "kind": "optional",
                "type": "map",
                "readOnly": true,
                "description": "<p>Map of rule/ruleset count associated with the variation in each environment that includes environment key as key and count as value</p>",
                "example": "{\"development\":15,\"production\":20}",
                "customType": "map<string, integer>",
                "schema": []
              },
              {
                "name": "fetch_flag_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "Link to flag url of this variation",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "flag_key",
                "kind": "required",
                "type": "string",
                "description": "The Key of the Flag this Variation belongs to"
              },
              {
                "name": "id",
                "kind": "required",
                "type": "integer",
                "readOnly": true,
                "description": "System generated Unique ID of the Variation"
              },
              {
                "name": "in_use",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "Indicates if the Variation is in use by a rule or a ruleset"
              },
              {
                "name": "key",
                "kind": "required",
                "type": "string",
                "description": "<p>User-facing Unique identifier of the Variation</p>"
              },
              {
                "name": "name",
                "kind": "required",
                "type": "string",
                "description": "<p>User-facing name of the Variation</p>"
              },
              {
                "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": "screenshot_name",
                "kind": "optional",
                "type": "string",
                "nullable": true,
                "description": "Original filename of the uploaded screenshot image. Null when no screenshot has been attached.",
                "example": "hero-banner.png",
                "maxLength": 255
              },
              {
                "name": "screenshot_url",
                "kind": "optional",
                "type": "string",
                "nullable": true,
                "description": "<p>Backend proxy path to the variation's uploaded screenshot image. Null when no screenshot has been attached. Format: /projects/{project_id}/files/{file_id}</p>",
                "example": "/projects/123/files/a1b2c3d4-e5f6-7890-abcd-ef1234567890",
                "maxLength": 2000
              },
              {
                "name": "unarchive_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "Link to unarchive this Variation",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "update_url",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "Link to update this Variation",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "updated_time",
                "kind": "required",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "Timestamp when the Variation is updated",
                "format": "date-time"
              },
              {
                "name": "url",
                "kind": "required",
                "type": "object",
                "readOnly": true,
                "description": "Link to self",
                "complexType": "allOf",
                "complexItems": [
                  {
                    "name": "UrlValue",
                    "description": "",
                    "modelRef": "#/components/schemas/UrlValue",
                    "schema": []
                  }
                ],
                "schema": []
              },
              {
                "name": "urn",
                "kind": "required",
                "type": "string",
                "readOnly": true,
                "description": "The URN for the Variation"
              },
              {
                "name": "variables",
                "kind": "optional",
                "type": "map",
                "description": "Map of flag variables that include variable key and value",
                "example": "",
                "customType": "map<string, VariableValue>",
                "schema": []
              }
            ],
            "modelRef": "#/components/schemas/Variation",
            "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": "example-0-curl",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variations \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"key\": \"high_discount\",\n     \"name\": \"High Discount\"\n     }'"
        },
        {
          "id": "example-1-javascript",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"key\": \"high_discount\",\n   \"name\": \"High Discount\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variations\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "example-2-ruby",
          "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}/variations\")\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\"\nrequest.body = JSON.dump({\n   \"key\": \"high_discount\",\n   \"name\": \"High Discount\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "example-3-python",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/flags/v1//projects/{project_id}/flags/{flag_key}/variations\"\n\npayload = json.dumps({\n   \"key\": \"high_discount\",\n   \"name\": \"High Discount\"\n})\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": "example-0-curl"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-201",
          "language": "201",
          "code": "// Successful retrieval, creation or update of a Variation for a Flag.\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  \"archive_url\": {},\n  \"archived\": false,\n  \"created_time\": \"\",\n  \"delete_url\": {},\n  \"description\": \"\",\n  \"enabled\": false,\n  \"environment_usage_count\": \"{\\\"development\\\":15,\\\"production\\\":20}\",\n  \"fetch_flag_url\": {},\n  \"flag_key\": \"\",\n  \"id\": 0,\n  \"in_use\": false,\n  \"key\": \"\",\n  \"name\": \"\",\n  \"revision\": 0,\n  \"role\": \"admin\",\n  \"screenshot_name\": \"hero-banner.png\",\n  \"screenshot_url\": \"/projects/123/files/a1b2c3d4-e5f6-7890-abcd-ef1234567890\",\n  \"unarchive_url\": {},\n  \"update_url\": {},\n  \"updated_time\": \"\",\n  \"url\": {},\n  \"urn\": \"\",\n  \"variables\": \"\"\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-201"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}