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