0

Get Lists on a Board

by
Published Oct 30, 2023

Get the Lists on a Board

Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Get Lists on a Board
7
 * Get the Lists on a Board
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  cards: "all" | "closed" | "none" | "open" | undefined,
13
  card_fields: string | undefined,
14
  filter: "all" | "closed" | "none" | "open" | undefined,
15
  fields: string | undefined
16
) {
17
  const url = new URL(`https://api.trello.com/1/boards/${id}/lists`);
18
  for (const [k, v] of [
19
    ["cards", cards],
20
    ["card_fields", card_fields],
21
    ["filter", filter],
22
    ["fields", fields],
23
    ["key", auth.key],
24
    ["token", auth.token],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: undefined,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43