0

Create Sheet in Workspace

by
Published Oct 17, 2025

Creates a sheet from scratch or from the specified template at the top-level of the specified workspace. For subfolders, use Create Sheet in 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 Workspace
8
 * Creates a sheet from scratch or from the specified template at the top-level of the specified workspace.
9
For subfolders, use Create Sheet in Folder.
10

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