Wix Business Tools events are fired in your site's backend when certain events occur in your site's Business Tools application. You can write event handlers that react to these events. Event handler functions receive data that correspond to the event that has occurred. Use event handlers to create custom responses to events.
To add an 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:
For example, an event handler that handles a location update looks like this:
Note: Backend events don't work when previewing your site.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Triggered when a location is archived.
function wixLocations_onLocationArchiveStatus(
event: LocationArchiveStatus,
): void;
Contains information about the archived location and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixLocations_onLocationArchiveStatus(event) {
const archivedTime = event.metadata.eventTime;
console.log(
`Location was archived at ${archivedTime}. Event details:`,
event,
);
}
/* Full event object:
* {
* "data": {
* "_id": "489d0ea1-9eb4-4215-9616-98e297c7337e"
* },
* "metadata": {
* "entityId": "489d0ea1-9eb4-4215-9616-98e297c7337e",
* "eventTime": "2023-11-13T08\:00\:47.696025Z",
* "id": "a92d9e8b-abd7-4903-a954-5a6848f6f4eb",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn't return any custom errors, but may return standard errors. Learn more about standard Wix errors.