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