0

Create a Listing for Plugin

by
Published Oct 30, 2023

Create a new listing for a given locale for your Power-Up

Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Create a Listing for Plugin
7
 * Create a new listing for a given locale for your Power-Up
8
 */
9
export async function main(
10
  auth: Trello,
11
  idPlugin: string,
12
  body: {
13
    description?: string;
14
    locale?: string;
15
    overview?: string;
16
    name?: string;
17
    [k: string]: unknown;
18
  }
19
) {
20
  const url = new URL(`https://api.trello.com/1/plugins/${idPlugin}/listing`);
21
  for (const [k, v] of [
22
    ["key", auth.key],
23
    ["token", auth.token],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: undefined,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43