0

Get a Label

by
Published Oct 30, 2023

Get information about a single Label.

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