1 | |
2 | type Miro = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Copy board |
7 | * Creates a copy of an existing board. You can also update the name, description, sharing policy, and permissions policy for the new board in the request body.Required scope boards:write Rate limiting Level 4 |
8 | */ |
9 | export async function main( |
10 | auth: Miro, |
11 | copy_from: string | undefined, |
12 | body: { |
13 | description?: string; |
14 | name?: string; |
15 | policy?: { |
16 | permissionsPolicy?: { |
17 | collaborationToolsStartAccess?: |
18 | | "all_editors" |
19 | | "board_owners_and_coowners"; |
20 | copyAccess?: "anyone" | "team_members" | "team_editors" | "board_owner"; |
21 | sharingAccess?: |
22 | | "team_members_with_editing_rights" |
23 | | "owner_and_coowners"; |
24 | }; |
25 | sharingPolicy?: { |
26 | access?: "private" | "view" | "edit" | "comment"; |
27 | inviteToAccountAndBoardLinkAccess?: |
28 | | "viewer" |
29 | | "commenter" |
30 | | "editor" |
31 | | "no_access"; |
32 | organizationAccess?: "private" | "view" | "edit" | "comment"; |
33 | teamAccess?: "private" | "view" | "edit" | "comment"; |
34 | }; |
35 | }; |
36 | teamId?: string; |
37 | }, |
38 | ) { |
39 | const url = new URL(`https://api.miro.com//v2/boards`); |
40 | for (const [k, v] of [["copy_from", copy_from]]) { |
41 | if (v !== undefined && v !== "" && k !== undefined) { |
42 | url.searchParams.append(k, v); |
43 | } |
44 | } |
45 | const response = await fetch(url, { |
46 | method: "PUT", |
47 | headers: { |
48 | "Content-Type": "application/json", |
49 | Authorization: "Bearer " + auth.token, |
50 | }, |
51 | body: JSON.stringify(body), |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.json(); |
58 | } |
59 |
|