---
title: Create a Custom Event
slug: feature-experimentation/api/create-a-custom-event
docTags: 
createdAt: 2026-10-01T19:58:02.336Z
---

{
  "id": "8IZzzLqbi6CRdkAoqTo9q",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.optimizely.com/v2/projects/{project_id}/custom_events",
    "servers": [
      {
        "url": "https://api.optimizely.com/v2/projects/{project_id}/custom_events"
      }
    ],
    "name": "Create a Custom Event",
    "description": "Create a Custom Event in a provided Project",
    "contentType": "application/json",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "project_id",
          "type": "integer<int64>",
          "description": "The Project ID of the Project you want to create an Custom Event in",
          "format": "int64"
        }
      ],
      "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 a Custom Event",
          "customType": "CustomEvent",
          "schema": [
            {
              "name": "archived",
              "kind": "optional",
              "type": "boolean",
              "description": "Whether or not to archive this Event"
            },
            {
              "name": "category",
              "kind": "optional",
              "type": "string",
              "description": "",
              "modelRef": "#/components/schemas/EventCategories",
              "customType": "EventCategories",
              "schema": [
                {
                  "name": "name",
                  "kind": "optional",
                  "type": "string",
                  "description": ""
                }
              ]
            },
            {
              "name": "description",
              "kind": "optional",
              "type": "string",
              "description": "A description of this Event"
            },
            {
              "name": "event_properties",
              "kind": "optional",
              "type": "array",
              "description": "<p>A set of user-defined data elements for the event. Metrics can filter on particular values of these properties.</p>",
              "modelRef": "#/components/schemas/EventProperty",
              "customType": "EventProperty[]",
              "schema": [
                {
                  "name": "data_type",
                  "kind": "optional",
                  "type": "string<boolean | number | string>",
                  "description": "The type of data that can be accepted for this property.",
                  "enum": [
                    "boolean",
                    "number",
                    "string"
                  ]
                },
                {
                  "name": "name",
                  "kind": "optional",
                  "type": "string",
                  "description": "The name of the property."
                }
              ]
            },
            {
              "name": "event_type",
              "kind": "optional",
              "type": "string<custom>",
              "description": "The type of this Event",
              "enum": [
                "custom"
              ]
            },
            {
              "name": "key",
              "kind": "required",
              "type": "string",
              "description": "Unique string identifier for this Event within the Project",
              "example": "loaded_new_app",
              "maxLength": 64,
              "pattern": "^[a-zA-Z0-9_\\- .]+$"
            },
            {
              "name": "name",
              "kind": "optional",
              "type": "string",
              "description": "<p>A human readable name for this Event. If unspecified, defaults to the key</p>",
              "example": "Loaded New App"
            }
          ],
          "modelRef": "#/components/schemas/CustomEvent",
          "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 Custom Event",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "CustomEvent",
            "schema": [
              {
                "name": "archived",
                "kind": "optional",
                "type": "boolean",
                "description": "Whether or not to archive this Event"
              },
              {
                "name": "category",
                "kind": "optional",
                "type": "string",
                "description": "",
                "modelRef": "#/components/schemas/EventCategories",
                "customType": "EventCategories",
                "schema": [
                  {
                    "name": "name",
                    "kind": "optional",
                    "type": "string",
                    "description": ""
                  }
                ]
              },
              {
                "name": "created",
                "kind": "optional",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "Creation date for this Event",
                "format": "date-time"
              },
              {
                "name": "description",
                "kind": "optional",
                "type": "string",
                "description": "A description of this Event"
              },
              {
                "name": "event_properties",
                "kind": "optional",
                "type": "array",
                "description": "<p>A set of user-defined data elements for the event. Metrics can filter on particular values of these properties.</p>",
                "modelRef": "#/components/schemas/EventProperty",
                "customType": "EventProperty[]",
                "schema": [
                  {
                    "name": "data_type",
                    "kind": "optional",
                    "type": "string<boolean | number | string>",
                    "description": "The type of data that can be accepted for this property.",
                    "enum": [
                      "boolean",
                      "number",
                      "string"
                    ]
                  },
                  {
                    "name": "name",
                    "kind": "optional",
                    "type": "string",
                    "description": "The name of the property."
                  }
                ]
              },
              {
                "name": "event_type",
                "kind": "optional",
                "type": "string<custom>",
                "description": "The type of this Event",
                "enum": [
                  "custom"
                ]
              },
              {
                "name": "id",
                "kind": "optional",
                "type": "integer<int64>",
                "readOnly": true,
                "description": "The unique identifier of the Event",
                "format": "int64"
              },
              {
                "name": "is_classic",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "<p>Whether or not this Event is a classic Event. If true, this Event is read-only</p>",
                "default": false
              },
              {
                "name": "is_editable",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "Whether or not this Event may be edited"
              },
              {
                "name": "key",
                "kind": "required",
                "type": "string",
                "description": "Unique string identifier for this Event within the Project",
                "example": "loaded_new_app",
                "maxLength": 64,
                "pattern": "^[a-zA-Z0-9_\\- .]+$"
              },
              {
                "name": "name",
                "kind": "optional",
                "type": "string",
                "description": "<p>A human readable name for this Event. If unspecified, defaults to the key</p>",
                "example": "Loaded New App"
              },
              {
                "name": "project_id",
                "kind": "optional",
                "type": "integer<int64>",
                "readOnly": true,
                "description": "The ID of this Event's parent Project",
                "example": 1000,
                "format": "int64"
              }
            ],
            "modelRef": "#/components/schemas/CustomEvent",
            "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 access to 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": "gBckazk_ITfU1M3oQZ7FS",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.optimizely.com/v2/projects/{project_id}/custom_events \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"key\": \"loaded_new_app\"\n     }'"
        },
        {
          "id": "IDkPdNz_jXpHchONsCx9f",
          "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\": \"loaded_new_app\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.optimizely.com/v2/projects/{project_id}/custom_events\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "m4N5LRnFT3NVeMixwPO5k",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.optimizely.com/v2/projects/{project_id}/custom_events\")\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\": \"loaded_new_app\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "9eAPaBkerA_FiBFqXIdTY",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.optimizely.com/v2/projects/{project_id}/custom_events\"\n\npayload = json.dumps({\n   \"key\": \"loaded_new_app\"\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": "gBckazk_ITfU1M3oQZ7FS"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-201",
          "language": "201",
          "code": "// Return the created Custom Event\n{\n  \"archived\": false,\n  \"category\": \"\",\n  \"created\": \"\",\n  \"description\": \"\",\n  \"event_properties\": [\n    {\n      \"data_type\": \"\",\n      \"name\": \"\"\n    }\n  ],\n  \"event_type\": \"\",\n  \"id\": \"\",\n  \"is_classic\": false,\n  \"is_editable\": false,\n  \"key\": \"loaded_new_app\",\n  \"name\": \"Loaded New App\",\n  \"project_id\": 1000\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 access to 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": ""
    }
  ]
}