0

Get checkItem on a Card

by
Published Oct 30, 2023

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