0

Update Comment Action on a Card

by
Published Oct 30, 2023

Update an existing comment

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 Comment Action on a Card
7
 * Update an existing comment
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  idAction: string,
13
  text: string | undefined
14
) {
15
  const url = new URL(
16
    `https://api.trello.com/1/cards/${id}/actions/${idAction}/comments`
17
  );
18
  for (const [k, v] of [
19
    ["text", text],
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: "PUT",
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