0

Update Sheet

by
Published Oct 17, 2025

Updates the sheet specified in the URL. To modify sheet contents, see Add Rows, Update Rows, Add Columns, and Update Column. This operation can be used to update an individual user's sheet settings. If the request body contains only the **userSettings** attribute, this operation may be performed even if the user only has read-only access to the sheet (for example, the user has viewer permissions or the sheet is read-only).

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
 * Update Sheet
8
 * Updates the sheet specified in the URL.
9
To modify sheet contents, see Add Rows, Update Rows, Add Columns, and Update Column.
10
This operation can be used to update an individual user's sheet settings. If the request body contains only the **userSettings** attribute, this operation may be performed even if the user only has read-only access to the sheet (for example, the user has viewer permissions or the sheet is read-only).
11
 */
12
export async function main(
13
  auth: Smartsheet,
14
  sheetId: string,
15
  accessApiLevel: string | undefined,
16
  body: {
17
    name?: string;
18
    projectSettings?: {
19
      lengthOfDay?: number;
20
      nonWorkingDays?: string[];
21
      workingDays?:
22
        | "MONDAY"
23
        | "TUESDAY"
24
        | "WEDNESDAY"
25
        | "THURSDAY"
26
        | "FRIDAY"
27
        | "SATURDAY"
28
        | "SUNDAY"[];
29
    };
30
    userSettings?: {
31
      criticalPathEnabled?: false | true;
32
      displaySummaryTasks?: false | true;
33
    };
34
  },
35
) {
36
  const url = new URL(`${auth.baseUrl}/sheets/${sheetId}`);
37
  for (const [k, v] of [["accessApiLevel", accessApiLevel]]) {
38
    if (v !== undefined && v !== "" && k !== undefined) {
39
      url.searchParams.append(k, v);
40
    }
41
  }
42
  const response = await fetch(url, {
43
    method: "PUT",
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