0

Enable a Power-Up on a Board

by
Published Oct 30, 2023

Enable a Power-Up on a Board

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