List attribute values for a list entry
One script reply has been approved by the moderators Verified

Gets all values for a given attribute on a list entry. If the attribute is historic, this endpoint has the ability to return all historic values using the show_historic query param.

Required scopes: list_entry:read, list_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 attribute values for a list entry
7
 * Gets all values for a given attribute on a list entry. If the attribute is historic, this endpoint has the ability to return all historic values using the `show_historic` query param.
8

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