List notes
One script reply has been approved by the moderators Verified

List notes for all records or for a specific record.

Required scopes: note:read, object_configuration:read, record_permission:read.

Created by hugo697 141 days ago
Submitted by hugo697 Bun
Verified 141 days ago
1
//native
2
type Attio = {
3
  token: string;
4
};
5
/**
6
 * List notes
7
 * List notes for all records or for a specific record.
8

9
Required scopes: `note:read`, `object_configuration:read`, `record_permission:read`.
10
 */
11
export async function main(
12
  auth: Attio,
13
  limit: string | undefined,
14
  offset: string | undefined,
15
  parent_object: string | undefined,
16
  parent_record_id: string | undefined,
17
) {
18
  const url = new URL(`https://api.attio.com/v2/notes`);
19
  for (const [k, v] of [
20
    ["limit", limit],
21
    ["offset", offset],
22
    ["parent_object", parent_object],
23
    ["parent_record_id", parent_record_id],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42