0

Create Workspace

by
Published Oct 17, 2025

Creates a new workspace.

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 Workspace
8
 * Creates a new workspace.
9

10
 */
11
export async function main(
12
  auth: Smartsheet,
13
  accessApiLevel: string | undefined,
14
  include:
15
    | "all"
16
    | "attachments"
17
    | "brand"
18
    | "cellLinks"
19
    | "data"
20
    | "discussions"
21
    | "filters"
22
    | "forms"
23
    | "ruleRecipients"
24
    | "rules"
25
    | "shares"
26
    | undefined,
27
  skipRemap: "cellLinks" | "reports" | "sheetHyperlinks" | "sights" | undefined,
28
  body: {
29
    id?: number;
30
    name?: string;
31
    accessLevel?:
32
      | "ADMIN"
33
      | "COMMENTER"
34
      | "EDITOR"
35
      | "EDITOR_SHARE"
36
      | "OWNER"
37
      | "VIEWER";
38
    permalink?: string;
39
  },
40
) {
41
  const url = new URL(`${auth.baseUrl}/workspaces`);
42
  for (const [k, v] of [
43
    ["accessApiLevel", accessApiLevel],
44
    ["include", include],
45
    ["skipRemap", skipRemap],
46
  ]) {
47
    if (v !== undefined && v !== "" && k !== undefined) {
48
      url.searchParams.append(k, v);
49
    }
50
  }
51
  const response = await fetch(url, {
52
    method: "POST",
53
    headers: {
54
      "Content-Type": "application/json",
55
      Authorization: "Bearer " + auth.token,
56
    },
57
    body: JSON.stringify(body),
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65