0

Create a comment

by
Published Oct 17, 2025

Creates a new comment related to an existing thread, record or entry. To create comments on records, you will need the `object_configuration:read` and `record_permission:read` scopes. To create comments on list entries, you will need the `list_configuration:read` and `list_entry:read` scopes. Required scopes: `comment:read-write`.

Script attio Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Attio = {
3
  token: string;
4
};
5
/**
6
 * Create a comment
7
 * Creates a new comment related to an existing thread, record or entry.
8

9
To create comments on records, you will need the `object_configuration:read` and `record_permission:read` scopes.
10

11
To create comments on list entries, you will need the `list_configuration:read` and `list_entry:read` scopes.
12

13
Required scopes: `comment:read-write`.
14
 */
15
export async function main(
16
  auth: Attio,
17
  body: {
18
    data:
19
      | {
20
          format: "plaintext";
21
          content: string;
22
          author: { type: "workspace-member"; id: string };
23
          created_at?: string;
24
          thread_id: string;
25
        }
26
      | {
27
          format: "plaintext";
28
          content: string;
29
          author: { type: "workspace-member"; id: string };
30
          created_at?: string;
31
          record: { object: string; record_id: string };
32
        }
33
      | {
34
          format: "plaintext";
35
          content: string;
36
          author: { type: "workspace-member"; id: string };
37
          created_at?: string;
38
          entry: { list: string; entry_id: string };
39
        };
40
  },
41
) {
42
  const url = new URL(`https://api.attio.com/v2/comments`);
43

44
  const response = await fetch(url, {
45
    method: "POST",
46
    headers: {
47
      "Content-Type": "application/json",
48
      Authorization: "Bearer " + auth.token,
49
    },
50
    body: JSON.stringify(body),
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.json();
57
}
58