0

Updating Plugin's Listing

by
Published Oct 30, 2023

Update an existing listing for your Power-Up

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
 * Updating Plugin's Listing
7
 * Update an existing listing for your Power-Up
8
 */
9
export async function main(
10
  auth: Trello,
11
  idPlugin: string,
12
  idListing: string,
13
  body: {
14
    description?: string;
15
    locale?: string;
16
    overview?: string;
17
    name?: string;
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(
22
    `https://api.trello.com/1/plugins/${idPlugin}/listings/${idListing}`
23
  );
24
  for (const [k, v] of [
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: "PUT",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: undefined,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46