1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Add a Sticker to a Card |
7 | * Add a sticker to a card |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | image: string | undefined, |
13 | top: string | undefined, |
14 | left: string | undefined, |
15 | zIndex: string | undefined, |
16 | rotate: string | undefined |
17 | ) { |
18 | const url = new URL(`https://api.trello.com/1/cards/${id}/stickers`); |
19 | for (const [k, v] of [ |
20 | ["image", image], |
21 | ["top", top], |
22 | ["left", left], |
23 | ["zIndex", zIndex], |
24 | ["rotate", rotate], |
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: "POST", |
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 |
|