> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-feat-user-history-moderation-detail.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Comment

> Choose the right comment creation API for text comments, replies, and image comments.

Use comment creation APIs to add comments to posts, stories, or your own custom content IDs. A reply is a normal comment with `parentId` set to the comment being replied to.

<CardGroup cols={2}>
  <Card title="Text Comment" href="./text-comment" icon="message-square">
    Create top-level comments and replies with text, metadata, mentions, and supported link payloads.
  </Card>

  <Card title="Image Comment" href="./image-comment" icon="image">
    Create comments with uploaded image file IDs.
  </Card>
</CardGroup>

## Parameters

| Parameter | Required | Platforms | Description |
| - | - | - | - |
| `referenceId` | Yes | TypeScript, iOS, Android, Flutter | Target content ID for the comment, such as a post ID. |
| `referenceType` | Yes | TypeScript, iOS, Android, Flutter | Target content type, such as `post`. |
| `text` | Yes | TypeScript, iOS, Android, Flutter | Text body for the comment or reply shown in these examples. |
| `parentId` | No | TypeScript, iOS, Android, Flutter | Parent comment ID when creating a reply. |
| `metadata` | No | TypeScript, iOS, Android, Flutter | App-defined metadata stored with the comment. Set through each platform's comment builder. |
| `mentionees` / mention builders | No | TypeScript, iOS, Android, Flutter | Mention targets for text comments. Set through each platform's comment builder. |

<Note>
  In a community that requires comment review, the created comment comes back with a `pending` approval status: only its author and the community's reviewers can see it, and it does not move the post's comment count for anyone else until it is approved. See [Approval Lifecycle](../moderation/comment-review#approval-lifecycle) for when a comment is held and who is exempt. In a community that requires review, create with optimistic creation turned off so the returned comment already carries its approval status — see [Read Approval Status on a Comment](../moderation/comment-review#read-approval-status-on-a-comment).
</Note>

## Basic Text Comment

Create a top-level text comment by passing the reference target and text body to the comment repository.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { CommentRepository } from '@amityco/ts-sdk';

  const { data: comment } = await CommentRepository.createComment({
    referenceId: postId,
    referenceType: 'post',
    data: {
      text: 'Hello world!',
    },
  });

  renderResults(comment);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentCreateOptions(
      referenceId: "post-id",
      referenceType: .post,
      text: "Hello world!"
  )

  let comment = try await commentRepository.createComment(with: options)
  showSuccessMessage(comment.commentId)
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId = postId)
      .with()
      .text(text = "Hello world!")
      .build()
      .send()
      .subscribe(
          { comment -> showSuccessMessage(comment.getCommentId()) },
          { error -> handleGeneralError(error) },
      )
  ```

  ```dart Flutter theme={null}
  final comment = await AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId)
      .create()
      .text('Hello world!')
      .send();

  final commentId = comment.commentId;
  ```
</CodeGroup>

## Reply to a Comment

Create a reply with the same reference target and the `parentId` of the comment being replied to.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { CommentRepository } from '@amityco/ts-sdk';

  const { data: reply } = await CommentRepository.createComment({
    referenceId: postId,
    referenceType: 'post',
    parentId: commentId,
    data: {
      text: 'Replying to this comment',
    },
  });

  renderResults(reply);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentCreateOptions(
      referenceId: "post-id",
      referenceType: .post,
      text: "Replying to this comment",
      parentId: "parent-comment-id"
  )

  let reply = try await commentRepository.createComment(with: options)
  showSuccessMessage(reply.commentId)
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId = postId)
      .parentId(parentId = commentId)
      .with()
      .text(text = "Replying to this comment")
      .build()
      .send()
      .subscribe(
          { reply -> showSuccessMessage(reply.getCommentId()) },
          { error -> handleGeneralError(error) },
      )
  ```

  ```dart Flutter theme={null}
  final reply = await AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId)
      .parentId(commentId)
      .create()
      .text('Replying to this comment')
      .send();

  final replyId = reply.commentId;
  ```
</CodeGroup>

## Related Topics

<CardGroup cols={2}>
  <Card title="Text Comment" href="./text-comment" icon="message-square">
    See full text-comment parameters and notes.
  </Card>

  <Card title="Image Comment" href="./image-comment" icon="image">
    Create comments with uploaded image attachments.
  </Card>

  <Card title="Query Comments" href="../retrieval/query-comments" icon="filter">
    Query top-level comments and reply threads.
  </Card>

  <Card title="Delete Comment" href="../actions/delete-comment" icon="trash">
    Remove comments after user or moderation actions.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.