> ## Documentation Index
> Fetch the complete documentation index at: https://velt.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Comment Annotations

Use this API to add comment annotations to a document within an organization.

* You can add comments on an elemement, text or page.
* You can provide HTML or text content.
* Additional filters can be applied using location IDs.

# Endpoint

`POST https://api.velt.dev/v1/commentannotations/add`

# Headers

**x-velt-api-key** `string` *required*

Your API key.

**x-velt-auth-token** `string` *required*

Your [Auth Token](https://velt.dev/docs/security/auth-tokens.md).

# Body

#### Params

**data** `Object` *required*

**properties**

**organizationId** `string` *required*

Organization ID

**documentId** `string` *required*

Document ID

**commentAnnotations** `Object[]` *required*

**properties**

**annotationId** `string`

Custom Annotation ID. If not provided, Velt will generate a unique ID for the annotation.

**location** `Object`

**properties**

**id** `string` *required*

Location ID

**locationName** `string`

Location Name

**targetElement** `Object`

Target Element

**properties**

**elementId** `string`

Element DOM Id

**targetText** `string`

Target Text. Provide this if you want to add comment annotation on the provided text content.

**occurrence** `number`

Occurrence. Provide this if you want to add comment annotation on a text content.

**selectAllContent** `boolean`

Select All Content. Provide this if you want to select and add comment annotation on the entire text content of the target elementId.

**commentData** `Object[]` *required*

Array of Comment Data

**properties**

**commentId** `number`

Custom Comment ID. If not provided, Velt will generate a unique ID for the comment.

**commentText** `string`

Comment content in plain text string

**commentHtml** `string`

Comment content in HTML string

**isCommentResolverUsed** `boolean`

Use this for self-hosting comments data. Set this as true if you are comments resolver data provider in the SDK.

**isCommentTextAvailable** `boolean`

Use this for self-hosting comments data. Set this as true if this comment will have text content. Sometimes, comments might only have attachments and in that case, set this as false.

**from** `User` *required*

User object from whom the comment is added

**createdAt** `number`

Created At timestamp (in milliseconds since epoch).

**lastUpdated** `number`

Last Updated timestamp (in milliseconds since epoch).

**taggedUserContacts** `Object[]`

Array of tagged user contacts

**properties**

**text** `string` *required*

Display text of the tagged user (e.g. "@Username")

**userId** `string` *required*

User ID of the tagged user

**contact** `Object` *required*

**properties**

**email** `string` *required*

Email of the tagged user

**name** `string` *required*

Name of the tagged user

**userId** `string` *required*

User ID of the tagged user

**status** `Status`

Status

**properties**

**id** `string` *required*

Status ID

**name** `string` *required*

Status Name

**type** `'default' | 'ongoing' | 'terminal'` *required*

Type.

**color** `string` *required*

Text and comment pin color

**lightColor** `string` *required*

Background color on the status indicator

**svg** `string`

Raw SVG of the icon. Either `svg` or `iconUrl` is required.

**iconUrl** `string`

Icon URL. Either `svg` or `iconUrl` is required.

**assignedTo** `User`

User object to whom the comment is assigned

**context** `Object`

Custom key/value metadata object

**createdAt** `number`

Created At timestamp (in milliseconds since epoch).

**lastUpdated** `number`

Last Updated timestamp (in milliseconds since epoch).

**priority** `Object`

Priority

**properties**

**id** `string` *required*

Priority ID

**color** `string` *required*

Priority Color

**name** `string` *required*

Priority Name

**lightColor** `string` *required*

Priority Light Color

## **Example Requests**

#### Add comment annotation by organizationId, documentId and location

```JSON theme={null}
{
  "data": {
    "organizationId": "yourOrganizationId",
    "documentId": "yourDocumentId",
    "commentAnnotations": [
      {
        "location": {
          "id": "yourLocationId",
          "locationName": "yourLocationName"
        },
        "targetElement": {
          "elementId": "yourElementId",
          "targetText": "Your Target Text",
          "occurrence": 1,
          "selectAllContent": false
        },
        "commentData": [
          {
            "commentText": "Sample Comment",
            "commentHtml": "<div>Sample Comment</div>",
            "from": {
              "userId": "yourUserId",
              "name": "yourUserName",
              "email": "yourUserEmail",
            }
          }
        ]
      }
    ]
  }
}
```

# Response

#### Success Response

```JSON theme={null}
{
   "result": {
       "status": "success",
       "message": "Comment Annotation(s) added successfully.",
       "data": {
           "-O0mpUziLcBwzREvZKs6": {
               "success": true,
               "annotationId": "-O0mpUziLcBwzREvZKs6",
               "commentIds": [
                   126535
               ],
               "message": "Added Successfully"
           }
       }
   }
}

```

#### Failure Response

```JSON theme={null}
{
  "error": {
    "message": "ERROR_MESSAGE",
    "status": "INVALID_ARGUMENT"
  }
}
```

```js theme={null}
{
   "result": {
       "status": "success",
       "message": "Comment Annotation(s) added successfully.",
       "data": {
           "-O0mpUziLcBwzREvZKs6": {
               "success": true,
               "annotationId": "-O0mpUziLcBwzREvZKs6",
               "commentIds": [
                   126535
               ],
               "message": "Added Successfully"
           }
       }
   }
}
```


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