0

Move all Cards in List

by
Published Oct 30, 2023

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