1 | |
2 | type Miro = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create items in bulk |
7 | * Adds different types of items to a board. |
8 | */ |
9 | export async function main( |
10 | auth: Miro, |
11 | board_id: string, |
12 | body: { |
13 | type: |
14 | | "app_card" |
15 | | "text" |
16 | | "shape" |
17 | | "sticky_note" |
18 | | "image" |
19 | | "document" |
20 | | "card" |
21 | | "frame" |
22 | | "embed"; |
23 | data?: |
24 | | { |
25 | description?: string; |
26 | fields?: { |
27 | fillColor?: string; |
28 | iconShape?: "round" | "square"; |
29 | iconUrl?: string; |
30 | textColor?: string; |
31 | tooltip?: string; |
32 | value?: string; |
33 | }[]; |
34 | owned?: false | true; |
35 | status?: "disconnected" | "connected" | "disabled"; |
36 | title?: string; |
37 | } |
38 | | { |
39 | assigneeId?: string; |
40 | description?: string; |
41 | dueDate?: string; |
42 | title?: string; |
43 | } |
44 | | { title?: string; url: string } |
45 | | { mode?: "inline" | "modal"; previewUrl?: string; url: string } |
46 | | { title?: string; url: string } |
47 | | { |
48 | content?: string; |
49 | shape?: |
50 | | "rectangle" |
51 | | "round_rectangle" |
52 | | "circle" |
53 | | "triangle" |
54 | | "rhombus" |
55 | | "parallelogram" |
56 | | "trapezoid" |
57 | | "pentagon" |
58 | | "hexagon" |
59 | | "octagon" |
60 | | "wedge_round_rectangle_callout" |
61 | | "star" |
62 | | "flow_chart_predefined_process" |
63 | | "cloud" |
64 | | "cross" |
65 | | "can" |
66 | | "right_arrow" |
67 | | "left_arrow" |
68 | | "left_right_arrow" |
69 | | "left_brace" |
70 | | "right_brace"; |
71 | } |
72 | | { content?: string; shape?: "square" | "rectangle" } |
73 | | { content: string }; |
74 | style?: |
75 | | { fillColor?: string } |
76 | | { cardTheme?: string } |
77 | | { |
78 | borderColor?: string; |
79 | borderOpacity?: string; |
80 | borderStyle?: "normal" | "dotted" | "dashed"; |
81 | borderWidth?: string; |
82 | color?: string; |
83 | fillColor?: string; |
84 | fillOpacity?: string; |
85 | fontFamily?: |
86 | | "arial" |
87 | | "abril_fatface" |
88 | | "bangers" |
89 | | "eb_garamond" |
90 | | "georgia" |
91 | | "graduate" |
92 | | "gravitas_one" |
93 | | "fredoka_one" |
94 | | "nixie_one" |
95 | | "open_sans" |
96 | | "permanent_marker" |
97 | | "pt_sans" |
98 | | "pt_sans_narrow" |
99 | | "pt_serif" |
100 | | "rammetto_one" |
101 | | "roboto" |
102 | | "roboto_condensed" |
103 | | "roboto_slab" |
104 | | "caveat" |
105 | | "times_new_roman" |
106 | | "titan_one" |
107 | | "lemon_tuesday" |
108 | | "roboto_mono" |
109 | | "noto_sans" |
110 | | "plex_sans" |
111 | | "plex_serif" |
112 | | "plex_mono" |
113 | | "spoof" |
114 | | "tiempos_text" |
115 | | "formular"; |
116 | fontSize?: string; |
117 | textAlign?: "left" | "right" | "center"; |
118 | textAlignVertical?: "top" | "middle" | "bottom"; |
119 | } |
120 | | { |
121 | fillColor?: |
122 | | "gray" |
123 | | "light_yellow" |
124 | | "yellow" |
125 | | "orange" |
126 | | "light_green" |
127 | | "green" |
128 | | "dark_green" |
129 | | "cyan" |
130 | | "light_pink" |
131 | | "pink" |
132 | | "violet" |
133 | | "red" |
134 | | "light_blue" |
135 | | "blue" |
136 | | "dark_blue" |
137 | | "black"; |
138 | textAlign?: "left" | "right" | "center"; |
139 | textAlignVertical?: "top" | "middle" | "bottom"; |
140 | } |
141 | | { |
142 | color?: string; |
143 | fillColor?: string; |
144 | fillOpacity?: string; |
145 | fontFamily?: |
146 | | "arial" |
147 | | "abril_fatface" |
148 | | "bangers" |
149 | | "eb_garamond" |
150 | | "georgia" |
151 | | "graduate" |
152 | | "gravitas_one" |
153 | | "fredoka_one" |
154 | | "nixie_one" |
155 | | "open_sans" |
156 | | "permanent_marker" |
157 | | "pt_sans" |
158 | | "pt_sans_narrow" |
159 | | "pt_serif" |
160 | | "rammetto_one" |
161 | | "roboto" |
162 | | "roboto_condensed" |
163 | | "roboto_slab" |
164 | | "caveat" |
165 | | "times_new_roman" |
166 | | "titan_one" |
167 | | "lemon_tuesday" |
168 | | "roboto_mono" |
169 | | "noto_sans" |
170 | | "plex_sans" |
171 | | "plex_serif" |
172 | | "plex_mono" |
173 | | "spoof" |
174 | | "tiempos_text" |
175 | | "formular"; |
176 | fontSize?: string; |
177 | textAlign?: "left" | "right" | "center"; |
178 | }; |
179 | position?: { x?: number; y?: number }; |
180 | geometry?: { height?: number; rotation?: number; width?: number }; |
181 | parent?: { id?: string }; |
182 | }[], |
183 | ) { |
184 | const url = new URL(`https://api.miro.com//v2/boards/${board_id}/items/bulk`); |
185 |
|
186 | const response = await fetch(url, { |
187 | method: "POST", |
188 | headers: { |
189 | "Content-Type": "application/json", |
190 | Authorization: "Bearer " + auth.token, |
191 | }, |
192 | body: JSON.stringify(body), |
193 | }); |
194 | if (!response.ok) { |
195 | const text = await response.text(); |
196 | throw new Error(`${response.status} ${text}`); |
197 | } |
198 | return await response.json(); |
199 | } |
200 |
|