1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a new Card |
7 | * Create a new card. Query parameters may also be replaced with a JSON request body instead. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | name: string | undefined, |
12 | desc: string | undefined, |
13 | pos: string | undefined, |
14 | due: string | undefined, |
15 | start: string | undefined, |
16 | dueComplete: string | undefined, |
17 | idList: string | undefined, |
18 | idMembers: string | undefined, |
19 | idLabels: string | undefined, |
20 | urlSource: string | undefined, |
21 | fileSource: string | undefined, |
22 | mimeType: string | undefined, |
23 | idCardSource: string | undefined, |
24 | keepFromSource: |
25 | | "all" |
26 | | "attachments" |
27 | | "checklists" |
28 | | "comments" |
29 | | "customFields" |
30 | | "due" |
31 | | "start" |
32 | | "labels" |
33 | | "members" |
34 | | "start" |
35 | | "stickers" |
36 | | undefined, |
37 | address: string | undefined, |
38 | locationName: string | undefined, |
39 | coordinates: string | undefined |
40 | ) { |
41 | const url = new URL(`https://api.trello.com/1/cards`); |
42 | for (const [k, v] of [ |
43 | ["name", name], |
44 | ["desc", desc], |
45 | ["pos", pos], |
46 | ["due", due], |
47 | ["start", start], |
48 | ["dueComplete", dueComplete], |
49 | ["idList", idList], |
50 | ["idMembers", idMembers], |
51 | ["idLabels", idLabels], |
52 | ["urlSource", urlSource], |
53 | ["fileSource", fileSource], |
54 | ["mimeType", mimeType], |
55 | ["idCardSource", idCardSource], |
56 | ["keepFromSource", keepFromSource], |
57 | ["address", address], |
58 | ["locationName", locationName], |
59 | ["coordinates", coordinates], |
60 | ["key", auth.key], |
61 | ["token", auth.token], |
62 | ]) { |
63 | if (v !== undefined && v !== "") { |
64 | url.searchParams.append(k, v); |
65 | } |
66 | } |
67 | const response = await fetch(url, { |
68 | method: "POST", |
69 | headers: { |
70 | Authorization: undefined, |
71 | }, |
72 | body: undefined, |
73 | }); |
74 | if (!response.ok) { |
75 | const text = await response.text(); |
76 | throw new Error(`${response.status} ${text}`); |
77 | } |
78 | return await response.json(); |
79 | } |
80 |
|