> 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`).
> - 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: Event Extension Files and Code

## Article: Event Extension Files and Code

## Article Link: https://dev.wix.com/docs/backend-extensions/backend-events/event-extension-files-and-code.md

## Article Content:

# Event Extension Files and Code

An event extension has two files:

- `<event-name>.extension.ts`: The configuration file. It calls the builder that declares the event extension.
- `<event-name>.ts`: The handler. It contains the code that runs when the event fires.

The `source` field in the configuration file points to the handler.

## Configuration file

The configuration file imports `extensions` and calls `extensions.event` with the extension's ID and the path to its handler.

Import `extensions` from the package your project uses:

```ts
// Studio Two site
import { extensions } from '@wix/custom-extensions';
```

```ts
// Wix CLI app or headless project
import { extensions } from '@wix/astro/builders';
```

```ts
export default extensions.event({
  id: '9912811d-5f5b-41f9-b4d6-ef4163b714a7',
  source: './extensions/backend/events/my-event/my-event.ts',
});
```

### Builder fields

| Field | Type | Description |
|-------|------|-------------|
| `id` | string | The extension's GUID. The Builder or the CLI generates it. |
| `source` | string | The path to the handler file, relative to `src/`. |

## Handler

The handler is the default export of the file. It calls an SDK event handler function for the event, and passes a function that Wix calls when the event occurs:

```ts
import { contacts } from '@wix/crm';

export default contacts.onContactCreated((event) => {
  // Add your logic here
});
```

Wix passes the event object to that function. The fields in the object depend on the event. For the payload of each event, see the event's page in the [API reference](https://dev.wix.com/docs/api-reference.md).

The handler runs with no caller identity. To call Wix APIs that need permissions, use [elevation](https://dev.wix.com/docs/overview/auth-permissions/elevation.md). Wix can deliver an event more than once, so write the handler to be idempotent. For delivery behavior, see [Events](https://dev.wix.com/docs/overview/backend-services/events.md).

## See also

- [About Event Extensions](https://dev.wix.com/docs/backend-extensions/backend-events/about-event-extensions.md)
- [Event Extensions](https://dev.wix.com/docs/overview/extensions-framework/backend-extensions/event-extensions.md)
- [Events](https://dev.wix.com/docs/overview/backend-services/events.md)