0

Get Checkitems on a Checklist

by
Published Oct 30, 2023
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 Checkitems on a Checklist
7
 *
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  filter: "all" | "none" | undefined,
13
  fields:
14
    | "all"
15
    | "name"
16
    | "nameData"
17
    | "pos"
18
    | "state"
19
    | "type"
20
    | "due"
21
    | "dueReminder"
22
    | "idMember"
23
    | undefined
24
) {
25
  const url = new URL(`https://api.trello.com/1/checklists/${id}/checkItems`);
26
  for (const [k, v] of [
27
    ["filter", filter],
28
    ["fields", fields],
29
    ["key", auth.key],
30
    ["token", auth.token],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: undefined,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.text();
48
}
49