---
title: Get Environments by Project
slug: web-experimentation/api/get-environments-by-project
docTags: 
createdAt: 2026-10-02T13:15:18.296Z
---

{
  "id": "e-BRMfNyJgTe2SKAT9umI",
  "type": "api-oas-v2",
  "data": {
    "method": "GET",
    "url": "https://api.optimizely.com/v2/environments",
    "servers": [
      {
        "url": "https://api.optimizely.com/v2/environments"
      }
    ],
    "name": "Get Environments by Project",
    "description": "Get all of the Environments that have been created in a given 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": [
        {
          "kind": "optional",
          "name": "per_page",
          "type": "integer",
          "description": "Optional pagination argument that specifies the maximum number of objects to return per request",
          "default": 25,
          "maximum": 100
        },
        {
          "kind": "optional",
          "name": "page",
          "type": "integer",
          "description": "Optional pagination argument that specifies the page to return. If you have 140 objects and you choose to return 100 objects per page you will be able to access the last 40 objects on page 2. The default value is 1.\n",
          "default": 1
        },
        {
          "kind": "required",
          "name": "project_id",
          "type": "integer<int64>",
          "description": "The ID of the project for which you would like to get Environments",
          "format": "int64"
        }
      ],
      "bodyDataParameters": [],
      "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": "200",
        "description": "Return all Environments in a specified Project",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "array",
            "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": "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 access to the Environments 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": "eUbRe8TxMn1E0KWvOSoJ4",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request GET \\\n     --url 'https://api.optimizely.com/v2/environments?per_page=25&page=1&project_id=integer%3Cint64%3E' \\\n     --header 'accept: application/json'"
        },
        {
          "id": "wcIv5MjVEoDD2pVmvMKN-",
          "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/v2/environments?per_page=25&page=1&project_id=integer<int64>\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "lpmAvrv_mtonicBfMyImN",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.optimizely.com/v2/environments?per_page=25&page=1&project_id=integer<int64>\")\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": "xSsa0isFqRPLB8i82gFaB",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/v2/environments?per_page=25&page=1&project_id=integer<int64>\"\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": "eUbRe8TxMn1E0KWvOSoJ4"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Return all Environments in a specified Project\n[\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  }\n]"
        },
        {
          "id": "response-1-401",
          "language": "401",
          "code": "// Invalid credentials\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        },
        {
          "id": "response-2-403",
          "language": "403",
          "code": "// You do not have permission to access to the Environments in the specified Project\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        },
        {
          "id": "response-3-default",
          "language": "default",
          "code": "// Unexpected error\n{\n  \"code\": \"\",\n  \"message\": \"\",\n  \"messages\": {},\n  \"uuid\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}