0

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