Introduction

 

Developer Preview
APIs in Developer Preview are subject to change and are not intended for use in production.
Send us your suggestions for improving this API. Your feedback is valuable to us.

 

Wix CRM events are fired in your site's backend when certain events related to site contacts occur in your site's backend. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to contact related events.

Note: Backend events don't work when previewing your site.

To add a CRM event handler, add an events.js file to the Backend section of your site if one does not already exist. All event handler functions for your site are defined in this file.

Event handler functions are defined using the following pattern:

Copy

For example, an event handler that handles contact updates looks like this:

Copy
Did this help?

onContactCreated( )


Triggered when a contact is created.

Method Declaration
Copy
Method Parameters
eventContactCreated

Information about the contact that was created and metadata for the event.

An event fired when a contact is created
JavaScript
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onContactDeleted( )


Triggered when a contact is deleted.

If a contact is deleted as part of a merge, the originatedFrom property is sent as merge. Otherwise, originatedFrom isn't returned.

Method Declaration
Copy
Method Parameters
eventContactDeleted

Metadata for the event.

An event fired when a contact is deleted
JavaScript
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onContactMerged( )


Triggered when one or more source contacts are merged into a target contact.

Method Declaration
Copy
Method Parameters
eventContactMergedEvent

Information about the source and target contacts, and metadata for the event.

An event fired when a contact is merged
JavaScript
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onContactUpdated( )


Triggered when a contact is updated.

Method Declaration
Copy
Method Parameters
eventContactUpdated

Information about the contact that was updated and metadata for the event.

An event fired when a contact is updated
JavaScript
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onLabelCreated( )


Triggered when a label is created.

Method Declaration
Copy
Method Parameters
eventLabelCreated

Information about the task that was created and metadata for the event.

An event fired when a label is created
JavaScript
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onLabelDeleted( )


Triggered when a label is deleted.

Method Declaration
Copy
function wixContacts_onLabelDeleted(event: LabelDeleted): void;
Method Parameters
eventLabelDeleted

Metadata for the event.

An event fired when a label is deleted
JavaScript
// Place this code in the events.js file // of your site's Backend section. // Add the file if it doesn't exist. export function wixContacts_onLabelDeleted(event) { console.log("Label deleted", event); } /* Full event object: * { * "metadata": { * "id": "64c54bac-5c9c-42b6-b43b-9143e6814b50", * "entityId": "custom.customer-group-3", * "eventTime": "2024-01-11T12:47:31.862945419Z", * "triggeredByAnonymizeRequest": false * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?