0

Create a new custom Board Background

by
Published Oct 30, 2023

Upload a new custom board background

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