Subchapter 2.28
references/BACKEND_EVENT.mdMarkdown3 KBView on GitHub
Event extensions run custom logic when something happens on a site — a contact is created, an order is placed, a booking is confirmed, a blog post is published. Each extension is built on a Wix JavaScript SDK webhook; the CLI subscribes your project to it.
Common use cases: react to CRM events, sync data on order creation, send notifications when a booking is confirmed.
Use wix generate --params with all required fields:
wix generate --params '{"extensionType":"EVENT","folder":"<folder>"}'folder must be lowercase alphanumeric and hyphens. The CLI generates the folder, both files, the UUID, and the src/extensions.ts registration. The scaffolded handler file imports a sample SDK event (CRM Contact Created) — replace the import and the handler body with the event you actually want.
| Topic | Reference |
|---|---|
| Common events (CRM, eCommerce, Bookings, Blog) | COMMON-EVENTS.md |
Each handler imports an event from the relevant @wix/* SDK module and is default-exported (e.g., export default contacts.onContactCreated((event) => { ... })). See COMMON-EVENTS.md for the SDK module, handler name, payload shape, and required permission for each common event. Handlers can be async; wrap logic in try/catch so one failing handler doesn’t break others.
When calling Wix APIs from inside an event handler, use auth.elevate from @wix/essentials so the call runs with the right permissions.
import { contacts } from "@wix/crm";
import { auth } from "@wix/essentials";
import { items } from "@wix/data";
export default contacts.onContactCreated(async (event) => {
const elevatedQuery = auth.elevate(items.query);
const result = await elevatedQuery("MyCollection").find();
// Use result
});console.log for debugging; keep production logs minimal and non-sensitive.