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

Lists entries in a given list, with the option to filter and sort results.

Required scopes: list_entry:read, list_configuration: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 entries
7
 * Lists entries in a given list, with the option to filter and sort results.
8

9
Required scopes: `list_entry:read`, `list_configuration:read`.
10
 */
11
export async function main(
12
  auth: Attio,
13
  list: string,
14
  body: {
15
    filter?: {};
16
    sorts?:
17
      | { direction: "asc" | "desc"; attribute: string; field?: string }
18
      | { direction: "asc" | "desc"; path: string[][]; field?: string }[];
19
    limit?: number;
20
    offset?: number;
21
  },
22
) {
23
  const url = new URL(`https://api.attio.com/v2/lists/${list}/entries/query`);
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39