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

Lists all attributes defined on a specific object or list. Attributes are returned in the order that they are sorted by in the UI.

Required scopes: object_configuration:read.

Created by hugo697 51 days ago
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
type Attio = {
3
  token: string;
4
};
5
/**
6
 * List attributes
7
 * Lists all attributes defined on a specific object or list. Attributes are returned in the order that they are sorted by in the UI.
8

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