0

Delete a Webhook

by
Published Oct 30, 2023

Delete a webhook by ID.

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