0

Get a Checklist

by
Published Oct 30, 2023
Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Get a Checklist
7
 *
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  cards: "all" | "closed" | "none" | "open" | "visible" | undefined,
13
  checkItems: "all" | "none" | undefined,
14
  checkItem_fields:
15
    | "all"
16
    | "name"
17
    | "nameData"
18
    | "pos"
19
    | "state"
20
    | "type"
21
    | "due"
22
    | "dueReminder"
23
    | "idMember"
24
    | undefined,
25
  fields: string | undefined
26
) {
27
  const url = new URL(`https://api.trello.com/1/checklists/${id}`);
28
  for (const [k, v] of [
29
    ["cards", cards],
30
    ["checkItems", checkItems],
31
    ["checkItem_fields", checkItem_fields],
32
    ["fields", fields],
33
    ["key", auth.key],
34
    ["token", auth.token],
35
  ]) {
36
    if (v !== undefined && v !== "") {
37
      url.searchParams.append(k, v);
38
    }
39
  }
40
  const response = await fetch(url, {
41
    method: "GET",
42
    headers: {
43
      Authorization: undefined,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.text();
52
}
53