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 Comments events are fired in your site's backend when certain events occur with plans. 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 pricing plan events.

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

To add a comments 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
export function <wixAppName>_<eventName>(event) { }

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

Copy
export function wixComments_onCommentUpdated(event) {}
Did this help?

onCommentDeleted( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Method Declaration
Copy
function wixCommentsV2_onCommentDeleted(event: CommentDeleted): void;
Method Parameters
eventCommentDeleted
onCommentDeleted example
JavaScript
export function wixCommentsV2_onCommentDeleted(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

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

Did this help?

onCommentCreated( )


Triggered when a comment is created.

Method Declaration
Copy
function wixComments_onCommentCreated(event: CommentCreated): void;
Method Parameters
eventCommentCreated
onCommentCreated example
JavaScript
export function wixComments_onCommentCreated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

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

Did this help?

onCommentDeleted( )


Triggered when a comment is deleted.

Method Declaration
Copy
function wixComments_onCommentDeleted(event: CommentDeletedEvent): void;
Method Parameters
eventCommentDeletedEvent
onCommentDeleted example
JavaScript
export function wixCommentsV2_onCommentDeleted(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

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

Did this help?

onCommentMarked( )


Triggered when a comment is marked.

Method Declaration
Copy
function wixComments_onCommentMarked(event: CommentMarkedEvent): void;
Method Parameters
eventCommentMarkedEvent
onCommentMarked example
JavaScript
export function wixComments_onCommentMarked(event) { const eventId = event.metadata.id; const entityId = event.data.comment._id; }
Errors

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

Did this help?

onCommentUnmarked( )


Triggered when a comment is unmarked.

Method Declaration
Copy
function wixComments_onCommentUnmarked(event: CommentUnmarkedEvent): void;
Method Parameters
eventCommentUnmarkedEvent
onCommentUnmarked example
JavaScript
export function wixComments_onCommentUnmarked(event) { const eventId = event.metadata.id; const entityId = event.data.comment._id; }
Errors

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

Did this help?