0

Update a Webhook created by Token

by
Published Oct 30, 2023

Update a Webhook created by Token

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 a Webhook created by Token
7
 * Update a Webhook created by Token
8
 */
9
export async function main(
10
  auth: Trello,
11
  token: string,
12
  idWebhook: string,
13
  description: string | undefined,
14
  callbackURL: string | undefined,
15
  idModel: string | undefined
16
) {
17
  const url = new URL(
18
    `https://api.trello.com/1/tokens/${token}/webhooks/${idWebhook}`
19
  );
20
  for (const [k, v] of [
21
    ["description", description],
22
    ["callbackURL", callbackURL],
23
    ["idModel", idModel],
24
    ["key", auth.key],
25
    ["token", auth.token],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "PUT",
33
    headers: {
34
      Authorization: undefined,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.text();
43
}
44