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

<ParamField header="x-velt-api-key" type="string" required>
  Your API key.
</ParamField>

<ParamField header="x-velt-auth-token" type="string" required>
  Your [Auth Token](/security/auth-tokens).
</ParamField>

# Body

#### Params

<ParamField body="data" type="Object" required>
  <Expandable title="properties">
    <ParamField body="organizationId" type="string" required>
      Organization ID
    </ParamField>

    <ParamField body="documentId" type="string" required>
      Document ID
    </ParamField>

    <ParamField body="commentAnnotations" type="Object[]" required>
      <Expandable title="properties">
        <ParamField body="annotationId" type="string">
          Custom Annotation ID. If not provided, Velt will generate a unique ID for the annotation.
        </ParamField>

        <ParamField body="location" type="Object">
          <Expandable title="properties">
            <ParamField body="id" type="string" required>
              Location ID
            </ParamField>

            <ParamField body="locationName" type="string">
              Location Name
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="targetElement" type="Object">
          Target Element

          <Expandable title="properties">
            <ParamField body="elementId" type="string">
              Element DOM Id
            </ParamField>

            <ParamField body="targetText" type="string">
              Target Text. Provide this if you want to add comment annotation on the provided text content.
            </ParamField>

            <ParamField body="occurrence" type="number">
              Occurrence. Provide this if you want to add comment annotation on a text content.
            </ParamField>

            <ParamField body="selectAllContent" type="boolean">
              Select All Content. Provide this if you want to select and add comment annotation on the entire text content of the target elementId.
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="commentData" type="Object[]" required>
          Array of Comment Data

          <Expandable title="properties">
            <ParamField body="commentId" type="number">
              Custom Comment ID. If not provided, Velt will generate a unique ID for the comment.
            </ParamField>

            <ParamField body="commentText" type="string">
              Comment content in plain text string
            </ParamField>

            <ParamField body="commentHtml" type="string">
              Comment content in HTML string
            </ParamField>

            <ParamField body="isCommentResolverUsed" type="boolean">
              Use this for self-hosting comments data. Set this as true if you are comments resolver data provider in the SDK.
            </ParamField>

            <ParamField body="isCommentTextAvailable" type="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.
            </ParamField>

            <ParamField body="from" type="User" required>
              User object from whom the comment is added
            </ParamField>

            <ParamField body="createdAt" type="number">
              Created At timestamp (in milliseconds since epoch).
            </ParamField>

            <ParamField body="lastUpdated" type="number">
              Last Updated timestamp (in milliseconds since epoch).
            </ParamField>

            <ParamField body="taggedUserContacts" type="Object[]">
              Array of tagged user contacts

              <Expandable title="properties">
                <ParamField body="text" type="string" required>
                  Display text of the tagged user (e.g. "@Username")
                </ParamField>

                <ParamField body="userId" type="string" required>
                  User ID of the tagged user
                </ParamField>

                <ParamField body="contact" type="Object" required>
                  <Expandable title="properties">
                    <ParamField body="email" type="string" required>
                      Email of the tagged user
                    </ParamField>

                    <ParamField body="name" type="string" required>
                      Name of the tagged user
                    </ParamField>

                    <ParamField body="userId" type="string" required>
                      User ID of the tagged user
                    </ParamField>
                  </Expandable>
                </ParamField>
              </Expandable>
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="status" type="Status">
          Status

          <Expandable title="properties">
            <ParamField body="id" type="string" required>
              Status ID
            </ParamField>

            <ParamField body="name" type="string" required>
              Status Name
            </ParamField>

            <ParamField body="type" type="'default' | 'ongoing' | 'terminal'" required>
              Type.
            </ParamField>

            <ParamField body="color" type="string" required>
              Text and comment pin color
            </ParamField>

            <ParamField body="lightColor" type="string" required>
              Background color on the status indicator
            </ParamField>

            <ParamField body="svg" type="string">
              Raw SVG of the icon. Either `svg` or `iconUrl` is required.
            </ParamField>

            <ParamField body="iconUrl" type="string">
              Icon URL. Either `svg` or `iconUrl` is required.
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="assignedTo" type="User">
          User object to whom the comment is assigned
        </ParamField>

        <ParamField body="context" type="Object">
          Custom key/value metadata object
        </ParamField>

        <ParamField body="createdAt" type="number">
          Created At timestamp (in milliseconds since epoch).
        </ParamField>

        <ParamField body="lastUpdated" type="number">
          Last Updated timestamp (in milliseconds since epoch).
        </ParamField>

        <ParamField body="priority" type="Object">
          Priority

          <Expandable title="properties">
            <ParamField body="id" type="string" required>
              Priority ID
            </ParamField>

            <ParamField body="color" type="string" required>
              Priority Color
            </ParamField>

            <ParamField body="name" type="string" required>
              Priority Name
            </ParamField>

            <ParamField body="lightColor" type="string" required>
              Priority Light Color
            </ParamField>
          </Expandable>
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

## **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"
  }
}
```

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