1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Copy Folder |
8 | * Copies a folder. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | folderId: string, |
13 | include: |
14 | | "attachments" |
15 | | "cellLinks" |
16 | | "data" |
17 | | "discussions" |
18 | | "filters" |
19 | | "forms" |
20 | | "ruleRecipients" |
21 | | "rules" |
22 | | "shares" |
23 | | undefined, |
24 | exclude: "sheetHyperlinks" | undefined, |
25 | skipRemap: "cellLinks" | "reports" | "sheetHyperlinks" | "sights" | undefined, |
26 | body: { |
27 | destinationId: number; |
28 | destinationType?: "folder" | "home" | "workspace"; |
29 | newName?: string; |
30 | }, |
31 | ) { |
32 | const url = new URL(`${auth.baseUrl}/folders/${folderId}/copy`); |
33 | for (const [k, v] of [ |
34 | ["include", include], |
35 | ["exclude", exclude], |
36 | ["skipRemap", skipRemap], |
37 | ]) { |
38 | if (v !== undefined && v !== "" && k !== undefined) { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "POST", |
44 | headers: { |
45 | "Content-Type": "application/json", |
46 | Authorization: "Bearer " + auth.token, |
47 | }, |
48 | body: JSON.stringify(body), |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|