> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Add Event Extensions with the Wix CLI

## Article: Add Event Extensions with the Wix CLI

## Article Link: https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/backend/events/add-event-extensions-with-the-wix-cli.md

## Article Content:

# Add Event Extensions with the Wix CLI

Events are triggered when specific conditions occur in your project. These are conditions on a Wix user's site.
Your project can respond to these events using event extensions. Events in the Wix CLI are built on JavaScript SDK webhooks, and event extensions subscribe your project to these webhooks behind the scenes.

Learn more [about event extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/events/about-event-extensions.md).

> **Note:** Event extensions are built on [webhooks](https://dev.wix.com/docs/build-apps/develop-your-app/api-integrations/events-and-webhooks/about-webhooks.md). To learn how changes to event extensions reach the sites where your app is installed, see [webhooks and versioning](https://dev.wix.com/docs/build-apps/develop-your-app/api-integrations/events-and-webhooks/about-webhooks.md#webhooks-and-versioning).

Follow the instructions below to:

1. Create an event extension for your project.
2. Test the event extension in your project.
3. Deploy your project with the event extension.

Once this task is complete, your project will have an event extension that's triggered when a specific event occurs.

<blockquote class="important">

**Important:** 

You can't have 2 event extensions listening to the same event in your app. Each event can only have one handler. This includes extensions added to your app in the [app dashboard](https://manage.wix.com/account/custom-apps), not only those in the local files for your project.

</blockquote>

## Step 1 | Create the extension

In the terminal:

1. Navigate to your project repo.
2. Run the [generate](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/generate.md) command.

3. The CLI will display a menu of extensions to generate. Under **Backend**, select **Backend Event** and press Enter to continue.
4. The CLI will prompt you to name your event folder. This is the name of the folder in the project directory that contains the event code, and the name of the event. Only you will see this name.

Upon completion, the extension files will be created in your project directory with the following structure:

```bash
src/
  └── extensions/
      └── backend/
          └── events/
              └── <your-event-name>/
                  ├── <your-event-name>.extension.ts
                  └── <your-event-name>.ts
```

> **Note:** This is the default folder structure created by the CLI. You can move these files to any location within the `src/` folder and update the references in your `extensions.ts` file. Learn more about the [flexible file system](https://dev.wix.com/docs/wix-cli/cli-for-apps/project-structure/folders-and-files/src-extensions.md).

Learn more about [event extension files and code](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/backend/events/event-extension-files-and-code.md).

> **For app projects**: You may need to [configure permissions for your app](https://dev.wix.com/docs/build-apps/develop-your-app/access/authorization/configure-permissions-for-your-app.md) to receive the event.

<!-- Not currently supported
## Step 2 | Test your event extension

<blockquote class="important">

**Important:**
Currently, local development is not supported for all events in the Wix CLI. If you are unable to test your event in the local development environment as described in this step, you can still see it in action by pushing your changes to production. See [Build and deploy your project.](#build-and-deploy-your-project).

</blockquote>

To test your event extension, you must:

1. Add logging inside your backend logic.
2. Trigger the event.
3. View the logs in the terminal.

### Add logging inside your backend logic

Inside your event's `.ts` file, add a `console.log()` command to one of your functions. For example:

```tsx
import { contacts } from "@wix/crm";

export default contacts.onContactCreated((event) => {
  console.log("A contact was created.", event.entity);
});
```

### Trigger the event

The process for triggering an event depends on the type of event:

Events that can be triggered by actions in your project's dashboard can be triggered in the CLI's local development environment, in which case logs will be displayed in the CLI.

To trigger the event in the local development environment, you must navigate to your project's site or dashboard in your local development environment, then take an action that will trigger your event.

1. From your project's directory in the terminal, run the [dev](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/dev.md) command.

1. Click the link to open your project's dashboard or site in your browser, depending on where you need to trigger the event.
1. Take an action that will trigger your event. This action depends on your specific event.

### View the logs in the terminal

Navigate back to the CLI terminal and you will see the logs from your backend logic in the following form:

```ts
5:45:11 PM Your console log message.
```

> **Note:** You can't view logs from backend code in production. -->

## Step 2 | Test your event extension

To check that your event extension runs:

1. Make sure your project uses the latest version of the CLI. To check and update your CLI version, see [Keep the CLI up to date](https://dev.wix.com/docs/wix-cli/cli/about-the-cli.md#keep-the-cli-up-to-date).
2. Run the [`build`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/build.md) command and then run the [`preview`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/preview.md) command.
3. Open one of the preview links the CLI prints, select a development site, and click **Install App**. If your app is already installed on that site, clicking **Install App** updates it to the new preview.
4. On that site or in its dashboard, take an action that triggers your event.

## Build and deploy your project

Once your project is ready for production, you can [build and deploy](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/project-development/build-and-deploy.md) it.

>**Note:**
> When you release an app project, you release a new version of the app allowing you to publish the app to the [Wix App Market](https://www.wix.com/app-market) or install it on a site with a direct install URL. You can view [your app's versions](https://manage.wix.com/app-selector?title=Select+an+App&primaryButtonText=Select+Site&actionUrl=https%3A%2F%2Fdev.wix.com%2Fapps%2F%7BappId%7D%2Fversions-app) in the app dashboard.

## Delete an event extension

To delete an event extension from your project:

1. Delete the folder that contains your event extension's files.
2. Remove the import and `.use()` statements for the extension from the [`extensions.ts`](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/about-the-extensions-ts-file.md) file.

<blockquote class="important">

**For app projects:** 

If you already have a version of your app project, you must build and deploy the project again after removing the event extension files. 

</blockquote>

## See also

- [Event Extension Files and Code](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/backend/events/event-extension-files-and-code.md)
- [About Events](https://dev.wix.com/docs/build-apps/develop-your-app/api-integrations/events-and-webhooks/about-events.md)
- [About Event Extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/events/about-event-extensions.md)