> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/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 | Description                                                                                     |
| ------------------------------- | -------- | ----------------------------------------------------------------------------------------------- |
| `referenceId`                   | Yes      | Target content ID for the comment, such as a post ID.                                           |
| `referenceType`                 | Yes      | Target content type, such as `post`.                                                            |
| `text`                          | Yes      | Text body for the comment or reply shown in these examples.                                     |
| `parentId`                      | No       | Parent comment ID when creating a reply.                                                        |
| `metadata`                      | No       | App-defined metadata stored with the comment, where supported by the platform-specific builder. |
| `mentionees` / mention builders | No       | Mention targets for text comments, where supported by the platform-specific builder.            |

## 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>
