1 | |
2 | type Miro = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get boards |
7 | * Retrieves a list of boards accessible to the user associated with the provided access token. |
8 | */ |
9 | export async function main( |
10 | auth: Miro, |
11 | team_id: string | undefined, |
12 | project_id: string | undefined, |
13 | query: string | undefined, |
14 | owner: string | undefined, |
15 | limit: string | undefined, |
16 | offset: string | undefined, |
17 | sort: |
18 | | "default" |
19 | | "last_modified" |
20 | | "last_opened" |
21 | | "last_created" |
22 | | "alphabetically" |
23 | | undefined, |
24 | ) { |
25 | const url = new URL(`https://api.miro.com//v2/boards`); |
26 | for (const [k, v] of [ |
27 | ["team_id", team_id], |
28 | ["project_id", project_id], |
29 | ["query", query], |
30 | ["owner", owner], |
31 | ["limit", limit], |
32 | ["offset", offset], |
33 | ["sort", sort], |
34 | ]) { |
35 | if (v !== undefined && v !== "" && k !== undefined) { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | Authorization: "Bearer " + auth.token, |
43 | }, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|