---
title: Define a comment
slug: cms-12/api/defining-a-comment
docTags: 
createdAt: 2026-08-07T16:45:43.000Z
---

In the Optimizely Community API, a comment is represented with the `Comment` class.

An instance of the `Comment` class is constructed with:

- `Author` – The user submitting the comment identified with an instance of the Reference class. The author is assumed to be anonymous if an empty Reference is provided.
- `Body` – The content of the comment represented as a string.
- `Parent` – The entity to which the comment is related, identified with an instance of the Reference class. This parent may identify a resource, such as content, a product in your application, or another comment.
- `IsVisible` – Indicates whether this comment is intended to be presented within the application, represented as a Boolean.

An instance of the `Comment` class, contributed by an anonymous user, can be constructed as shown below:

```csharp
var parentContent = Reference.Create("resource://identifier/for/a/resource");
var body = "This is wonderful content!";
var isVisible = true;

var comment = new Comment(parentContent, body, isVisible);
```

An instance of the `Comment` class, contributed by a known user, can be constructed as shown below:

```csharp
var parentContent = Reference.Create("resource://identifier/for/a/resource");
var author = Reference.Create("user://identifier/for/a/user");
var body = "This is wonderful content!";
var isVisible = true;

var comment = new Comment(parentContent, author, body, isVisible);
```

If an instance of a comment is intended to be a reply to an existing comment, it can be constructed as shown below:

```csharp
Comment existingComment;

// ...

var parentComment = existingComment.Id.ToReference();
var author = Reference.Create("user://identifier/for/a/user");
var body = "This is wonderful content!";
var isVisible = true;

var comment = new Comment(parentComment, author, body, isVisible);
```

### Parents and ancestors

Comments are hierarchical, so share relationships with resources and other comments.

![](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/VYQ1UFAQBo7h7fJnxponT-20260722-173054.png "comment_tree.png")

A comment has a parental relationship. The parent of a comment is the entity to which the comment replies. That entity may be a resource, such as content, a product, or another comment. In the diagram above:

- The parent of *Comment 1* is *Resource*.
- The parent of *Comment 3a* is *Comment 3*.

A comment also has ancestral relationships. A comment's ancestor is any entity appearing in the comment's hierarchical lineage. As with the parental relationship, ancestors may include a resource, such as content or a product, and other comments.

In the diagram above:

- The ancestors of *Comment 1a* include *Resource* and *Comment 1*. Conversely, *Comment 1a* may be referred to as a descendant of *Resource* and *Comment 1*.
- The ancestors of *Comment 3* include only *Resource*.

The Optimizely Community API supports retrieving comments according to parent and ancestral relationships. See *Retrieve a Comment* in [Manage comments](docId\:Mec_0sQRYhS-QFAbVCKBi).

### Identify the parent of a comment

The parent of a comment may identify one of two things:

- A resource, such as content or a product in your application
- Another comment

A comment directly attributed to a particular application resource identifies that resource as its parent. In such a case, an instance of the Reference class is constructed to identify that resource and is specified through the Comment class's constructor. (For information about references, see *References and IDs* in [Discovering the platform](docId\:NKmGS-fLtRQIYLEWZfb69).

A comment representing a reply to an existing comment identifies the original comment as its parent. In these cases, an instance of the Reference class is constructed with the ID of the parent comment and specified through the `Comment` class's constructor.
