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

# Add Comment

> Post a comment as the access token's user, with optional mentions, threading, and attachments

## Endpoint

```
POST /v2/tasks/{task_id}/comment
```

## Authentication

This endpoint requires an OAuth access token. Send it as a bearer token:

```bash theme={null}
Authorization: Bearer your_access_token
```

**Required scope:** `tasks:write`

> [!NOTE]
>
> The comment is posted as the access token's user, and any attachments are uploaded as them too.

## Path Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `task_id` | integer | Yes | Unique identifier for the task |

## Request Body

The request body must be a JSON object with the following fields:

### Required Fields

| Field | Type | Description |
| - | - | - |
| `comment` | string | Comment text content |

### Optional Fields

| Field | Type | Description |
| - | - | - |
| `mention_user_ids` | array\[integer] | List of user IDs to mention in the comment |
| `reply_to` | integer | Activity log ID of an existing comment to reply to (for threading) |
| `attachments` | array\[object] | Files to attach to the comment (uploaded automatically) |
| `user_email` | string | Ignored on this endpoint. The comment is always posted as the access token's user |

### Attachment Object

Each item in the `attachments` array must contain:

| Field | Type | Description |
| - | - | - |
| `filename` | string | Filename including extension (e.g., `"report.pdf"`) |
| `base64_content` | string | Base64-encoded file content |

## Request Example

```bash cURL theme={null}
curl -X POST "https://platform.chamelio.ai/v2/tasks/12345/comment" \
  -H "Authorization: Bearer your_access_token" \
  -H "Content-Type: application/json" \
  -d '{
    "comment": "The contract has been reviewed and looks good.",
    "mention_user_ids": [42, 57],
    "attachments": [
      {
        "filename": "review-notes.pdf",
        "base64_content": "JVBERi0xLjQKMSAwIG9iago..."
      }
    ]
  }'
```

```python Python theme={null}
import requests

task_id = 12345

url = f"https://platform.chamelio.ai/v2/tasks/{task_id}/comment"
headers = {
    "Authorization": "Bearer your_access_token",
    "Content-Type": "application/json"
}

payload = {
    "comment": "The contract has been reviewed and looks good.",
    "mention_user_ids": [42, 57],
    "attachments": [
        {
            "filename": "review-notes.pdf",
            "base64_content": "JVBERi0xLjQKMSAwIG9iago..."
        }
    ]
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

```javascript JavaScript theme={null}
const taskId = 12345;

const response = await fetch(
  `https://platform.chamelio.ai/v2/tasks/${taskId}/comment`,
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer your_access_token',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      comment: 'The contract has been reviewed and looks good.',
      mention_user_ids: [42, 57],
      attachments: [
        {
          filename: 'review-notes.pdf',
          base64_content: 'JVBERi0xLjQKMSAwIG9iago...'
        }
      ]
    })
  }
);

const data = await response.json();
console.log(data);
```

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "success": true,
  "activity_log_id": 98765,
  "message": "Comment created successfully"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `success` | boolean | Whether the comment was created successfully |
| `activity_log_id` | integer | ID of the created activity log entry (use this as `reply_to` for threaded replies) |
| `message` | string | Success confirmation message |

## Error Responses

### 400 Bad Request

Returned when the access token has no user behind it.
`client_credentials` tokens act as the admin who created the application, so this applies only to
tokens issued before application creators were recorded.

```json theme={null}
{
  "detail": "client_credentials tokens are not associated with a user"
}
```

### 401 Unauthorized

Returned when the access token is missing, unknown, revoked, or expired, or when an `X-API-Key` was
sent instead of a bearer token. See [OAuth error responses](https://docs.chamelio.ai/api-reference/oauth-apps.md#error-responses).

```json theme={null}
{
  "detail": "Invalid access token"
}
```

### 403 Forbidden

Returned when the token lacks the required scope:

```json theme={null}
{
  "detail": "Insufficient scope; this endpoint requires: tasks:write"
}
```

Or when the user may not comment on this task:

```json theme={null}
{
  "detail": "You do not have access to this resource"
}
```

### 404 Not Found

Returned when the task does not exist.

```json theme={null}
{
  "detail": "Not found"
}
```

### 422 Validation Error

Returned when the request body is invalid or required fields are missing.

```json theme={null}
{
  "detail": [
    {
      "loc": ["body", "comment"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

### 429 Too Many Requests

Returned when your organization exceeds its per-minute request limit.

```json theme={null}
{
  "detail": "Rate limit exceeded"
}
```

### 500 Internal Server Error

Returned when the comment creation fails due to a server error.

```json theme={null}
{
  "detail": "Failed to create comment"
}
```

## Notes

> [!NOTE]
>
> The `activity_log_id` returned in the response can be used as the `reply_to` value in subsequent
> requests to create threaded conversations on a task.

> [!TIP]
>
> When a comment is posted, a [`flows.tasks.commented`](https://docs.chamelio.ai/api-reference/webhooks/flows/task-commented)
> webhook event is triggered, allowing external systems to react to new comments in real time.

> [!WARNING]
>
> Attachments are sent as base64-encoded content in the request body. For large files, consider the
> impact on request size and timeout limits.

## Use Cases

This endpoint is useful for:

* **Two-way chat integrations** - Relay a user's message from Slack or Teams, posted as that user
* **Threaded conversations** - Build reply chains using the `reply_to` field with `activity_log_id` values
* **File sharing** - Attach documents or reports to task comments programmatically
* **Correct authorship** - Ensure comments show the real person, not a shared integration account
