0

Create Sheet in Folder

by
Published Oct 17, 2025

Creates a sheet from scratch or from the specified template in the specified folder.

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
 * Create Sheet in Folder
8
 * Creates a sheet from scratch or from the specified template in the specified folder.
9

10
 */
11
export async function main(
12
  auth: Smartsheet,
13
  folderId: string,
14
  include:
15
    | "attachments"
16
    | "cellLinks"
17
    | "data"
18
    | "discussions"
19
    | "filters"
20
    | "forms"
21
    | "ruleRecipients"
22
    | "rules"
23
    | undefined,
24
  body:
25
    | {
26
        columns?: {
27
          autoNumberFormat?: {
28
            fill?: string;
29
            prefix?: string;
30
            startingNumber?: number;
31
            suffix?: string;
32
          };
33
          contactOptions?: { email?: string; name?: string }[];
34
          options?: string[];
35
          primary?: false | true;
36
          symbol?: string;
37
          systemColumnType?:
38
            | "AUTO_NUMBER"
39
            | "CREATED_BY"
40
            | "CREATED_DATE"
41
            | "MODIFIED_BY"
42
            | "MODIFIED_DATE";
43
          title?: string;
44
          type?:
45
            | "ABSTRACT_DATETIME"
46
            | "CHECKBOX"
47
            | "CONTACT_LIST"
48
            | "DATE"
49
            | "DATETIME"
50
            | "DURATION"
51
            | "MULTI_CONTACT_LIST"
52
            | "MULTI_PICKLIST"
53
            | "PICKLIST"
54
            | "PREDECESSOR"
55
            | "TEXT_NUMBER";
56
          width?: number;
57
        }[];
58
        name?: string;
59
      }
60
    | { fromId?: number; name?: string },
61
) {
62
  const url = new URL(`${auth.baseUrl}/folders/${folderId}/sheets`);
63
  for (const [k, v] of [["include", include]]) {
64
    if (v !== undefined && v !== "" && k !== undefined) {
65
      url.searchParams.append(k, v);
66
    }
67
  }
68
  const response = await fetch(url, {
69
    method: "POST",
70
    headers: {
71
      "Content-Type": "application/json",
72
      Authorization: "Bearer " + auth.token,
73
    },
74
    body: JSON.stringify(body),
75
  });
76
  if (!response.ok) {
77
    const text = await response.text();
78
    throw new Error(`${response.status} ${text}`);
79
  }
80
  return await response.json();
81
}
82