---
title: Create an Environment
slug: web-experimentation/api/create-an-environment
docTags: 
createdAt: 2026-10-02T13:15:18.296Z
---

{
  "id": "UJHmuvpJfOIQkPgDOK27d",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.optimizely.com/v2/environments",
    "servers": [
      {
        "url": "https://api.optimizely.com/v2/environments"
      }
    ],
    "name": "Create an Environment",
    "description": "Create an Environment in a provided Project",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "A string in JSON format that includes all the fields to create an Environment",
          "customType": "Environment",
          "schema": [
            {
              "name": "archived",
              "kind": "optional",
              "type": "boolean",
              "description": "Boolean representing whether the Environment is archived.",
              "example": false
            },
            {
              "name": "datafile",
              "kind": "optional",
              "type": "object",
              "description": "",
              "modelRef": "#/components/schemas/Datafile",
              "customType": "Datafile",
              "schema": [
                {
                  "name": "id",
                  "kind": "optional",
                  "type": "integer",
                  "readOnly": true,
                  "description": "ID of Datafile."
                },
                {
                  "name": "latest_file_size",
                  "kind": "optional",
                  "type": "integer",
                  "readOnly": true,
                  "description": "The current size in bytes of the Datafile."
                },
                {
                  "name": "other_urls",
                  "kind": "optional",
                  "type": "array",
                  "readOnly": true,
                  "description": "List of other URLs where this Datafile is also available.",
                  "example": "",
                  "itemType": "string",
                  "customType": "string[]",
                  "itemExample": "",
                  "itemDefault": ""
                },
                {
                  "name": "revision",
                  "kind": "optional",
                  "type": "integer",
                  "readOnly": true,
                  "description": "Current revision number."
                },
                {
                  "name": "sdk_key",
                  "kind": "optional",
                  "type": "string",
                  "readOnly": true,
                  "description": "Unique key to identify this specific Environment and Datafile programmatically in our SDKs."
                },
                {
                  "name": "url",
                  "kind": "optional",
                  "type": "string<url>",
                  "readOnly": true,
                  "description": "URL where this Datafile is available.",
                  "format": "url"
                }
              ]
            },
            {
              "name": "description",
              "kind": "optional",
              "type": "string",
              "description": "A short description of the Environment.",
              "example": "For testing purposes before deploying to Production"
            },
            {
              "name": "has_restricted_permissions",
              "kind": "optional",
              "type": "boolean",
              "description": "Boolean representing whether starting experiments should be restricted to publishers and above in this Environment.",
              "default": false
            },
            {
              "name": "key",
              "kind": "required",
              "type": "string",
              "description": "Unique string identifier for this Environment within the Project.",
              "maxLength": 64,
              "pattern": "^[a-zA-Z0-9_\\-]+$"
            },
            {
              "name": "name",
              "kind": "required",
              "type": "string",
              "description": "Name of the Environment.",
              "example": "Staging"
            },
            {
              "name": "priority",
              "kind": "optional",
              "type": "integer",
              "description": "Integer representing the priority of the Environment. This is used for ordering in the UI.",
              "example": 3
            },
            {
              "name": "project_id",
              "kind": "required",
              "type": "integer",
              "description": "ID of the project of the Environment."
            }
          ],
          "modelRef": "#/components/schemas/Environment",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "apiKey",
          "name": "apiKey",
          "kind": "optional",
          "type": "http",
          "scheme": "bearer"
        },
        {
          "id": "OAuth2",
          "name": "OAuth2",
          "kind": "optional",
          "type": "oauth2",
          "description": "<p>Write applications that authenticate with the REST API via OAuth 2.0. Or, to authenticate using a personal token, see <a href=\"https://docs.developers.optimizely.com/web/docs/personal-token\" target=\"_blank\">https://docs.developers.optimizely.com/web/docs/personal-token</a></p>",
          "oauth2Flows": {
            "authorizationCode": {
              "authorizationUrl": "https://app.optimizely.com/oauth2/authorize",
              "tokenUrl": "https://app.optimizely.com/oauth2/token",
              "scopes": {
                "all": "Full access to your account"
              }
            }
          },
          "requiredScopes": [
            "read",
            "write"
          ]
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "201",
        "description": "Return the created Environment",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "Environment",
            "schema": [
              {
                "name": "archived",
                "kind": "optional",
                "type": "boolean",
                "description": "Boolean representing whether the Environment is archived.",
                "example": false
              },
              {
                "name": "created",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "description": "Created time."
              },
              {
                "name": "datafile",
                "kind": "optional",
                "type": "object",
                "description": "",
                "modelRef": "#/components/schemas/Datafile",
                "customType": "Datafile",
                "schema": [
                  {
                    "name": "id",
                    "kind": "optional",
                    "type": "integer",
                    "readOnly": true,
                    "description": "ID of Datafile."
                  },
                  {
                    "name": "latest_file_size",
                    "kind": "optional",
                    "type": "integer",
                    "readOnly": true,
                    "description": "The current size in bytes of the Datafile."
                  },
                  {
                    "name": "other_urls",
                    "kind": "optional",
                    "type": "array",
                    "readOnly": true,
                    "description": "List of other URLs where this Datafile is also available.",
                    "example": "",
                    "itemType": "string",
                    "customType": "string[]",
                    "itemExample": "",
                    "itemDefault": ""
                  },
                  {
                    "name": "revision",
                    "kind": "optional",
                    "type": "integer",
                    "readOnly": true,
                    "description": "Current revision number."
                  },
                  {
                    "name": "sdk_key",
                    "kind": "optional",
                    "type": "string",
                    "readOnly": true,
                    "description": "Unique key to identify this specific Environment and Datafile programmatically in our SDKs."
                  },
                  {
                    "name": "url",
                    "kind": "optional",
                    "type": "string<url>",
                    "readOnly": true,
                    "description": "URL where this Datafile is available.",
                    "format": "url"
                  }
                ]
              },
              {
                "name": "description",
                "kind": "optional",
                "type": "string",
                "description": "A short description of the Environment.",
                "example": "For testing purposes before deploying to Production"
              },
              {
                "name": "has_restricted_permissions",
                "kind": "optional",
                "type": "boolean",
                "description": "Boolean representing whether starting experiments should be restricted to publishers and above in this Environment.",
                "default": false
              },
              {
                "name": "id",
                "kind": "optional",
                "type": "integer",
                "readOnly": true,
                "description": "ID of this Environment."
              },
              {
                "name": "is_primary",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "<p>Boolean representing if this is the primary (default) Environment.</p>"
              },
              {
                "name": "key",
                "kind": "required",
                "type": "string",
                "description": "Unique string identifier for this Environment within the Project.",
                "maxLength": 64,
                "pattern": "^[a-zA-Z0-9_\\-]+$"
              },
              {
                "name": "last_modified",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "description": "Last modification time."
              },
              {
                "name": "name",
                "kind": "required",
                "type": "string",
                "description": "Name of the Environment.",
                "example": "Staging"
              },
              {
                "name": "priority",
                "kind": "optional",
                "type": "integer",
                "description": "Integer representing the priority of the Environment. This is used for ordering in the UI.",
                "example": 3
              },
              {
                "name": "project_id",
                "kind": "required",
                "type": "integer",
                "description": "ID of the project of the Environment."
              }
            ],
            "modelRef": "#/components/schemas/Environment",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Invalid request body supplied",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "Error",
            "schema": [
              {
                "name": "code",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "message",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "messages",
                "kind": "optional",
                "type": "object",
                "description": "",
                "example": "",
                "schema": []
              },
              {
                "name": "uuid",
                "kind": "optional",
                "type": "string<uuid>",
                "description": "",
                "format": "uuid"
              }
            ],
            "modelRef": "#/components/schemas/Error",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "401",
        "description": "Invalid credentials",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "Error",
            "schema": [
              {
                "name": "code",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "message",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "messages",
                "kind": "optional",
                "type": "object",
                "description": "",
                "example": "",
                "schema": []
              },
              {
                "name": "uuid",
                "kind": "optional",
                "type": "string<uuid>",
                "description": "",
                "format": "uuid"
              }
            ],
            "modelRef": "#/components/schemas/Error",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "403",
        "description": "You do not have permission to create an Environment in the specified Project",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "Error",
            "schema": [
              {
                "name": "code",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "message",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "messages",
                "kind": "optional",
                "type": "object",
                "description": "",
                "example": "",
                "schema": []
              },
              {
                "name": "uuid",
                "kind": "optional",
                "type": "string<uuid>",
                "description": "",
                "format": "uuid"
              }
            ],
            "modelRef": "#/components/schemas/Error",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "default",
        "description": "Unexpected error",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "Error",
            "schema": [
              {
                "name": "code",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "message",
                "kind": "optional",
                "type": "string",
                "description": ""
              },
              {
                "name": "messages",
                "kind": "optional",
                "type": "object",
                "description": "",
                "example": "",
                "schema": []
              },
              {
                "name": "uuid",
                "kind": "optional",
                "type": "string<uuid>",
                "description": "",
                "format": "uuid"
              }
            ],
            "modelRef": "#/components/schemas/Error",
            "isExpanded": true
          }
        ]
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "C8BdYeXgQDCCX4ue9sM5a",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.optimizely.com/v2/environments \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"key\": \"\",\n     \"name\": \"Staging\",\n     \"project_id\": \"\"\n     }'"
        },
        {
          "id": "80D5i_s-OZWR5wiLFj1jn",
          "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\": \"\",\n   \"name\": \"Staging\",\n   \"project_id\": \"\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.optimizely.com/v2/environments\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "laqM6M1Oi4cZj_VOL-kWs",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.optimizely.com/v2/environments\")\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\": \"\",\n   \"name\": \"Staging\",\n   \"project_id\": \"\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "mTQnDnucj3fTwXdHnfvWD",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/v2/environments\"\n\npayload = json.dumps({\n   \"key\": \"\",\n   \"name\": \"Staging\",\n   \"project_id\": \"\"\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": "C8BdYeXgQDCCX4ue9sM5a"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-201",
          "language": "201",
          "code": "// Return the created Environment\n{\n  \"archived\": false,\n  \"created\": \"\",\n  \"datafile\": {\n    \"id\": 0,\n    \"latest_file_size\": 0,\n    \"other_urls\": [\n      \"\"\n    ],\n    \"revision\": 0,\n    \"sdk_key\": \"\",\n    \"url\": \"\"\n  },\n  \"description\": \"For testing purposes before deploying to Production\",\n  \"has_restricted_permissions\": false,\n  \"id\": 0,\n  \"is_primary\": false,\n  \"key\": \"\",\n  \"last_modified\": \"\",\n  \"name\": \"Staging\",\n  \"priority\": 3,\n  \"project_id\": 0\n}"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Invalid request body supplied\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        },
        {
          "id": "response-2-401",
          "language": "401",
          "code": "// Invalid credentials\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        },
        {
          "id": "response-3-403",
          "language": "403",
          "code": "// You do not have permission to create an Environment in the specified Project\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        },
        {
          "id": "response-4-default",
          "language": "default",
          "code": "// Unexpected error\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "response-0-201"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}