Add a new comment to a card
1
type Trello = {
2
key: string;
3
token: string;
4
};
5
/**
6
* Add a new comment to a Card
7
* Add a new comment to a card
8
*/
9
export async function main(auth: Trello, id: string, text: string | undefined) {
10
const url = new URL(`https://api.trello.com/1/cards/${id}/actions/comments`);
11
for (const [k, v] of [
12
["text", text],
13
["key", auth.key],
14
["token", auth.token],
15
]) {
16
if (v !== undefined && v !== "") {
17
url.searchParams.append(k, v);
18
}
19
20
const response = await fetch(url, {
21
method: "POST",
22
headers: {
23
Authorization: undefined,
24
},
25
body: undefined,
26
});
27
if (!response.ok) {
28
const text = await response.text();
29
throw new Error(`${response.status} ${text}`);
30
31
return await response.json();
32
33