---
title: Archive a Custom Field
slug: feature-experimentation/api/archive-a-custom-field
docTags: 
createdAt: 2026-08-28T15:54:06.731Z
---

{
  "id": "E3WyaNn9hqTRoTzhy2xcY",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields/{id}/archived",
    "servers": [
      {
        "url": "https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields/{id}/archived"
      }
    ],
    "name": "Archive a Custom Field",
    "description": "<p>Archive a custom field within the specified project. Archived fields are excluded from required-value enforcement; the <code>required</code> setting is preserved so it is restored on unarchive.</p>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "project_id",
          "type": "integer",
          "example": 12345,
          "description": "The project identifier"
        },
        {
          "kind": "required",
          "name": "id",
          "type": "integer<int64>",
          "description": "ID of the custom field to archive.",
          "format": "int64"
        }
      ],
      "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 of a Custom Field.</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": "Represents custom fields for entities\n",
            "customType": "CustomField",
            "schema": [
              {
                "name": "archived",
                "kind": "optional",
                "type": "boolean",
                "description": "Whether the custom field is archived. New custom fields are created as unarchived by default.",
                "example": false
              },
              {
                "name": "created_by_user_id",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "nullable": true,
                "description": "<p>Identifier of the user who created this custom field (often an email).</p>",
                "example": "user@company.com"
              },
              {
                "name": "created_time",
                "kind": "optional",
                "type": "string<date-time>",
                "readOnly": true,
                "nullable": true,
                "description": "Timestamp when the custom field was created.",
                "example": "2024-01-01T10:00:00.000Z",
                "format": "date-time"
              },
              {
                "name": "default_value",
                "kind": "optional",
                "type": "string",
                "description": "Default value for the custom field if applicable.",
                "example": "option1"
              },
              {
                "name": "description",
                "kind": "optional",
                "type": "string",
                "description": "Optional detailed description explaining the purpose and context of this CustomField.\nHelps team members understand what this CustomField is measuring.\n",
                "example": "Custom field to tag experiments owned by the analytics team",
                "maxLength": 1000
              },
              {
                "name": "entity_type",
                "kind": "required",
                "type": "string<flag | rule>",
                "description": "Type of entity the custom field is associated with",
                "example": "flag",
                "enum": [
                  "flag",
                  "rule"
                ]
              },
              {
                "name": "field_type",
                "kind": "required",
                "type": "string<text | number | boolean | link | label>",
                "description": "<p>The type of the custom field (e.g., text, number, boolean, link, label)</p>",
                "example": "text",
                "enum": [
                  "text",
                  "number",
                  "boolean",
                  "link",
                  "label"
                ]
              },
              {
                "name": "id",
                "kind": "required",
                "type": "integer",
                "readOnly": true,
                "description": "<p>System-generated unique identifier for the CustomField.</p>",
                "example": 12345
              },
              {
                "name": "key",
                "kind": "required",
                "type": "string",
                "description": "<p>Unique user-defined identifier for the CustomField within the project.\nMust contain only alphanumeric characters, underscores, and hyphens.</p>",
                "example": "analytics_team",
                "maxLength": 64,
                "pattern": "^[a-zA-Z0-9_\\-]+$"
              },
              {
                "name": "name",
                "kind": "required",
                "type": "string",
                "description": "<p>Human-readable name for the CustomField displayed in the UI.</p>",
                "example": "Analytics Team",
                "maxLength": 255
              },
              {
                "name": "project_id",
                "kind": "optional",
                "type": "integer<int64>",
                "readOnly": true,
                "description": "The unique identifier of the project this CustomField belongs to.",
                "example": 98765,
                "format": "int64"
              },
              {
                "name": "required",
                "kind": "required",
                "type": "boolean",
                "description": "Indicates if the custom field is required for the associated entity.",
                "example": false
              },
              {
                "name": "updated_time",
                "kind": "optional",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "Timestamp when the custom field was last updated.",
                "example": "2024-01-01T10:00:00.000Z",
                "format": "date-time"
              },
              {
                "name": "validation",
                "kind": "optional",
                "type": "object",
                "nullable": true,
                "description": "<p>Validation rules for the custom field if applicable.\nAllowed keys depend on field_type:</p>\n<ul>\n<li>text → max_length, regex</li>\n<li>number → min, max, decimal_places, use_thousand_separator</li>\n<li>label → field_options, allow_multi_select</li>\n<li>link → no validation fields</li>\n<li>boolean → no validation fields</li>\n</ul>",
                "example": "{\"max\":100,\"max_length\":255,\"min\":1}",
                "schema": [
                  {
                    "name": "allow_multi_select",
                    "kind": "optional",
                    "type": "boolean",
                    "description": "Whether multiple values can be selected for label fields.",
                    "example": false
                  },
                  {
                    "name": "decimal_places",
                    "kind": "optional",
                    "type": "integer",
                    "description": "Number of allowed decimal places for numeric values.",
                    "example": 2
                  },
                  {
                    "name": "field_options",
                    "kind": "optional",
                    "type": "array",
                    "description": "Allowed values for label fields.",
                    "example": "[\"US\",\"EU\",\"APAC\"]",
                    "itemType": "string",
                    "customType": "string[]",
                    "itemExample": "",
                    "itemDefault": ""
                  },
                  {
                    "name": "max",
                    "kind": "optional",
                    "type": "number",
                    "description": "Maximum value for number fields.",
                    "example": 100
                  },
                  {
                    "name": "max_length",
                    "kind": "optional",
                    "type": "integer",
                    "description": "Maximum length for string fields.",
                    "example": 255
                  },
                  {
                    "name": "min",
                    "kind": "optional",
                    "type": "number",
                    "description": "Minimum value for number fields.",
                    "example": 1
                  },
                  {
                    "name": "regex",
                    "kind": "optional",
                    "type": "string",
                    "description": "Regular expression that the input must match.",
                    "example": "^[A-Za-z0-9_-]+$"
                  },
                  {
                    "name": "use_thousand_separator",
                    "kind": "optional",
                    "type": "boolean",
                    "description": "<p>Whether thousand separators should be permitted/displayed.</p>",
                    "example": true
                  }
                ]
              }
            ],
            "modelRef": "#/components/schemas/CustomField",
            "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": "yTIr9s1eEfXtWOaudUC-R",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields/{id}/archived \\\n     --header 'accept: application/json'"
        },
        {
          "id": "6Nykn0534vTjGAVSqeA-h",
          "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: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields/{id}/archived\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "ghReveN0iULirztrbY-rw",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields/{id}/archived\")\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\"\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "q4XWdWm2QL-YFQqwUkmlU",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields/{id}/archived\"\n\npayload = {}\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": "yTIr9s1eEfXtWOaudUC-R"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Successful retrieval of a Custom Field.\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  \"created_by_user_id\": \"user@company.com\",\n  \"created_time\": \"2024-01-01T10:00:00.000Z\",\n  \"default_value\": \"option1\",\n  \"description\": \"Custom field to tag experiments owned by the analytics team\",\n  \"entity_type\": \"flag\",\n  \"field_type\": \"text\",\n  \"id\": 12345,\n  \"key\": \"analytics_team\",\n  \"name\": \"Analytics Team\",\n  \"project_id\": 98765,\n  \"required\": false,\n  \"updated_time\": \"2024-01-01T10:00:00.000Z\",\n  \"validation\": {\n    \"allow_multi_select\": false,\n    \"decimal_places\": 2,\n    \"field_options\": [\n      \"\"\n    ],\n    \"max\": 100,\n    \"max_length\": 255,\n    \"min\": 1,\n    \"regex\": \"^[A-Za-z0-9_-]+$\",\n    \"use_thousand_separator\": true\n  }\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": ""
    }
  ]
}