0

Update a field on a List

by
Published Oct 30, 2023

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