Search.../

createComment( )

Developer Preview

Creates a new comment.

Description

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.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function createComment(comment: Comment): Promise<Comment>

createComment Parameters

NAME
TYPE
DESCRIPTION
comment
Comment

Comment to create.

Returns

Created comment.

Return Type:

Promise<
Comment
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the comment was created.

_id
string

Comment ID.

_updatedDate
Date

Date and time the comment was last updated.

appId
string

ID of the app that the comment is added to.

author
CommentAuthor

Comment's author.

content
CommentContent

Published comment content.

contextId
string

ID of the specific context the comment is in response to.

Within some Wix apps, the contextId will be the same as the resourceId. For example in Wix Forum, the forumPostId is used as both the contextId and the resourceId.

contextType
string

Reserved for internal use.

marked
boolean

Whether the comment is marked.

parentComment
ParentComment

Parent comment information.

See Terminology for more information about parent comments.

rating
number

Comment rating.

reactionSummary
CommentReactionSummary

Summary of reactions.

replyCount
number

Amount of comments that reply to this comment.

resourceId
string

ID of the specific resource that the comment is in response to.

Within some Wix apps, the resourceId will be the same as the contextId. For example in Wix Forum, the forumPostId is used as both the resourceId and the contextId.

revision
string

Revision number, which increments by 1 each time the comment is updated.

To prevent conflicting changes, the current revision must be passed when updating the comment.

status
string

Comment status.

Supported values:

  • "PUBLISHED": This comment is published and publicly visible.
  • "DELETED": This comment is deleted.
  • "PENDING": This comment is pending moderation. Moderation is not currently supported.
  • "HIDDEN": This comment has been hidden by a site moderator.
voteSummary
VoteSummary

Summary of votes.

Was this helpful?

createComment example

Copy Code
1import { comments } from 'wix-comments.v2';
2
3 async function createComment(comment, options) {
4 try {
5 const result = await comments.createComment(comment, options);
6
7 return result;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12 }
13