0

Update a List

by
Published Oct 30, 2023

Update the properties of a List

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
 * Update a List
7
 * Update the properties of a List
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  name: string | undefined,
13
  closed: string | undefined,
14
  idBoard: string | undefined,
15
  pos: string | undefined,
16
  subscribed: string | undefined
17
) {
18
  const url = new URL(`https://api.trello.com/1/lists/${id}`);
19
  for (const [k, v] of [
20
    ["name", name],
21
    ["closed", closed],
22
    ["idBoard", idBoard],
23
    ["pos", pos],
24
    ["subscribed", subscribed],
25
    ["key", auth.key],
26
    ["token", auth.token],
27
  ]) {
28
    if (v !== undefined && v !== "") {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "PUT",
34
    headers: {
35
      Authorization: undefined,
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.text();
44
}
45