Introduction
The Comments API allows you to manage a customized commenting program that lets site visitors share feedback or engage in discussions around different types of resources, including blog posts, forum threads, or other site content.
With the Wix Comments API, you can:
- Allow commenting on any page of your site.
- Mark specific comments to highlight and feature to your readers.
- Engage with visitors who are not site members through guest commenting.
Integrations
The Comments API is fully integrated with several Wix solutions. Each integration uses a slightly different configuration to work with Comments.
The following table details the currently supported integrations:
Wix App | appId | contextId | resourceId |
---|---|---|---|
Wix Blog | 14bcded7-0066-7c35-14d7-466cb3f09103 | internalId | internalId |
Wix Comments | 91c9d6a7-6667-41fb-b0b4-7d3b3ff0b02e | contentId | contentId |
Wix Forum | 14724f35-6794-cd1a-0244-25fd138f9242 | forumPostId | forumPostId |
Wix Groups | 148c2287-c669-d849-d153-463c7486a694 | groupId | feedItemId |
Terminology
- Marked comments: When a comment's
marked
field is set toTRUE
, it indicates that the comment has been flagged or marked for special attention. No additional automated behavior or action is taken with the comment. However, you can manually filter for comments marked as such with thequeryComments()
function and highlight them to your visitors as needed. - Parent comments: Parent comments refer to comments that have subsequent comments directly responding to them. They serve as the original or initial comments in a conversation thread. The parent comment's unique identifier is stored in the
parentComment.id
field of the corresponding reply comment. - Replies: Replies are comments that are made in direct response to earlier comments within a discussion. They are specifically intended as responses to a particular parent comment and contribute to the ongoing conversation. Replies help maintain the hierarchical structure of comment threads and enhance the engagement and interactivity among users.
Setup
To use the Comments API, install the @wix/comments
package using npm or Yarn:
1npm install @wix/comments
or
1yarn add @wix/comments
Then import { comments }
from @wix/comments
:
1import { comments } from '@wix/comments'
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Counts comments, given the provided filtering.
For field support for filters and sorting, see the Supported Filters & Sorting table in the queryComments()
function.
Permission Scopes
For app development, you must have one of the following permission scopes:function countComments(appId: string, options: CountCommentsOptions): Promise<CountCommentsResponse>
App ID to count the comments of.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Creates a new comment.
The appId
, contextId
, and resourceId
are all required and associate the created comment with the specific
resource it responds to. See Integrations for a list of integrated scopes for these fields.
If the created comment is a direct response to another comment, the commentId
of the parent comment should be passed
as parentComment.id
in this comment's request. See Terminology for additional information on parent comments and replies.
Permission Scopes
For app development, you must have one of the following permission scopes:function createComment(comment: Comment): Promise<Comment>
Comment to create.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Deletes a comment.
This endpoint deletes the content
of the comment and sets its status
to DELETED
.
Permission Scopes
For app development, you must have one of the following permission scopes:function deleteComment(commentId: string): Promise<void>
ID of the Comment to delete.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Retrieves a comment.
Permission Scopes
For app development, you must have one of the following permission scopes:function getComment(commentId: string): Promise<Comment>
ID of the comment to retrieve.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Sets marked
to "TRUE"
to mark a comment.
You can then filter for marked comments with the queryComments()
function to apply customizations.
Permission Scopes
For app development, you must have one of the following permission scopes:function markComment(commentId: string): Promise<MarkCommentResponse>
ID of the comment to mark.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Creates a query to retrieve a list of comments.
The queryComments()
function builds a query to retrieve a list of comments and returns a CommentsQueryBuilder
object.
The returned object contains the query definition, which is typically used to run the query using the find()
function.
You can refine the query by chaining CommentsQueryBuilder
functions onto the query. CommentsQueryBuilder
functions enable you to sort, filter, and control the results that queryComments()
returns.
queryComments()
runs with the following CommentsQueryBuilder
default that you can override:
ascending("_id")
The functions that are chained to queryComments()
are applied in the order they are called. For example, if you apply ascending("voteSummary.netVoteCount")
and then ascending("replyCount")
, the results are sorted first by the "voteSummary.netVoteCount"
, and then, if there are multiple results with the same "voteSummary.netVoteCount"
, the items are sorted by "replyCount"
.
The following CommentsQueryBuilder
functions are supported for the queryComments()
function. For a full description of the comment object, see the object returned for the items
property in CommentsQueryResult
.
PROPERTY | SUPPORTED FILTERS & SORTING |
---|---|
_id | eq() ,ne() ,in() |
contextId | eq() ,ne() ,in() |
resourceId | eq() ,ne() ,in() |
author.userId | eq() ,ne() ,in() |
author.memberId | eq() ,ne() ,in() |
author.visitorId | eq() ,ne() ,in() |
parentComment.id | eq() ,ne() ,in() |
replyCount | eq() ,ne() ,lt() ,le() ,gt() ,ge() ,ascending() ,descending() |
voteSummary.netVoteCount | eq() ,ne() ,lt() ,le() ,gt() ,ge() ,ascending() ,descending() |
status | eq() ,ne() ,in() |
rating | eq() ,ne() ,lt() ,le() ,gt() ,ge() ,ascending() ,descending() |
reactionSummary.total | eq() ,ne() ,lt() ,le() ,gt() ,ge() ,ascending() ,descending() |
marked | eq() ,ne() ,ascending() ,descending() |
Permission Scopes
For app development, you must have one of the following permission scopes:function queryComments(appId: string): CommentsQueryBuilder
App ID to query comments for.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Sets marked
to "FALSE"
to unmark a comment.
Permission Scopes
For app development, you must have one of the following permission scopes:function unmarkComment(commentId: string): Promise<UnmarkCommentResponse>
ID of the comment to unmark.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Updates a comment.
Each time the comment is updated, revision
increments by 1. The current revision
must be
passed when updating the comment. This ensures you're working with the latest comment and
prevents unintended overwrites.
Permission Scopes
For app development, you must have one of the following permission scopes:function updateComment(_id: string, comment: UpdateComment): Promise<Comment>
Comment ID.