0

Copy Sheet

by
Published Oct 17, 2025

Creates a copy of the specified sheet.

Script smartsheet Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Smartsheet = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Copy Sheet
8
 * Creates a copy of the specified sheet.
9

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