---
title: Create events
slug: feature-experimentation/api/dIWv-create-events
docTags: 
createdAt: 2026-09-18T02:51:55.756Z
---

::::CodeDrawer{title="Create events" isResponseExpanded="true" autoGeneratedAnchorSlug="create-events" legacyHash="HrhnUddPYGlmFQVPoNG3Y"}
:::CodeblockTabsExamples
```javascript
// -------------------------------------------------------------------------- //
//                               Create events.                               //
// -------------------------------------------------------------------------- //

// ---------------------------- Add to cart event --------------------------- //
POST {{baseUrl}}/projects/{{projectId}}/custom_events
Content-Type: application/json
Authorization: {{token}}

{
  "event_type": "custom",
  "key": "add_to_cart",
  "description": "Event used to track users that have added the item to the cart."
}

###

// ------------------------- Started checkout event ------------------------- //
POST {{baseUrl}}/projects/{{projectId}}/custom_events
Content-Type: application/json
Authorization: {{token}}

{
  "event_type": "custom",
  "key": "started_checkout",
  "description": "Event used to track users that has started the checkout flow."
}

###

// ------------------------ Completed checkout event ------------------------ //
POST {{baseUrl}}/projects/{{projectId}}/custom_events
Content-Type: application/json
Authorization: {{token}}

{
  "event_type": "custom",
  "key": "completed_checkout",
  "description": "Event used to track users that has completed the checkout flow."
}
```
:::

:::CodeblockTabsResponses
```javascript
{"success":true}
```
:::
::::

Create three example events using the Create a [Custom Event API endpoint](https://docs.developers.optimizely.com/feature-experimentation/reference/create_custom_event).

## Prerequisite

Before running this request, you must follow the instructions to configure your [REST API cookbook](https://docs.developers.optimizely.com/feature-experimentation/reference/set-up-visual-basic-to-run-rest-api-calls).

## Create a file

Create a file named `create-events.rest` and copy and paste the recipe into the file.

## Configure API

`{{baseUrl}}`, `{{projectId}}`, and `{{token}}` are defined in the `settings.json` file. Ensure you have configured your Visual Studio Code project correctly. See [Configure the Visual Studio Code REST Client](https://docs.developers.optimizely.com/feature-experimentation/reference/set-up-visual-basic-to-run-rest-api-calls#configure-the-visual-studio-code-rest-client).

```json
POST {{baseUrl}}/projects/{{projectId}}/custom_events
Content-Type: application/json
Authorization: {{token}}
```

## Create add\_to\_cart event

Create an event with the key `add_to_cart`. Click **Send Request** in Visual Studio Code.

Copy and save the `event ID` for `add_to_cart`. You need it for the [Create an experiment](https://docs.developers.optimizely.com/feature-experimentation/recipes/6-create-experiment) recipe.

This API call corresponds to the following in the UI:

```json
{
  "event_type": "custom",
  "key": "add_to_cart",
  "description": "Event used to track users that have added the item to the cart."
}
```

## The `###` delimiter

The REST Client extension delimits multiple requests using `###`. See [Main features in the REST Client documentation](https://marketplace.visualstudio.com/items?itemName=humao.rest-client#main-features).

## Create started\_checkout event

Create an event with the key `started_checkout`. Click **Send Request** in Visual Studio Code.

This API call corresponds to the following in the UI:

```json
{
  "event_type": "custom",
  "key": "started_checkout",
  "description": "Event used to track users that has started the checkout flow."
}
```

## Create completed\_checkout event

Create an event with the key `completed_checkout`. Click **Send Request** in Visual Studio Code.

This API call corresponds to the following in the UI:

```json
{
  "event_type": "custom",
  "key": "completed_checkout",
  "description": "Event used to track users that has completed the checkout flow."
}
```
