0

Update a Sticker on a Card

by
Published Oct 30, 2023

Update a sticker on a card

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 Sticker on a Card
7
 * Update a sticker on a card
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  idSticker: string,
13
  top: string | undefined,
14
  left: string | undefined,
15
  zIndex: string | undefined,
16
  rotate: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.trello.com/1/cards/${id}/stickers/${idSticker}`
20
  );
21
  for (const [k, v] of [
22
    ["top", top],
23
    ["left", left],
24
    ["zIndex", zIndex],
25
    ["rotate", rotate],
26
    ["key", auth.key],
27
    ["token", auth.token],
28
  ]) {
29
    if (v !== undefined && v !== "") {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "PUT",
35
    headers: {
36
      Authorization: undefined,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.text();
45
}
46