0

Add Columns

by
Published Oct 17, 2025

Inserts one or more columns into the sheet specified in the URL.This operation can be performed using a simple upload or a multipart upload. For more information, see Post an Attachment.

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
 * Add Columns
8
 * Inserts one or more columns into the sheet specified in the URL.This operation can be performed using a simple upload or a multipart upload. For more information, see Post an Attachment.
9
 */
10
export async function main(
11
  auth: Smartsheet,
12
  sheetId: string,
13
  body: {
14
    title?: string;
15
    type?:
16
      | "ABSTRACT_DATETIME"
17
      | "CHECKBOX"
18
      | "CONTACT_LIST"
19
      | "DATE"
20
      | "DATETIME"
21
      | "DURATION"
22
      | "MULTI_CONTACT_LIST"
23
      | "MULTI_PICKLIST"
24
      | "PICKLIST"
25
      | "PREDECESSOR"
26
      | "TEXT_NUMBER";
27
    formula?: string;
28
    hidden?: false | true;
29
    index?: number;
30
    autoNumberFormat?: {
31
      fill?: string;
32
      prefix?: string;
33
      startingNumber?: number;
34
      suffix?: string;
35
    };
36
    contactOptions?: { email?: string; name?: string };
37
    description?: string;
38
    format?: string;
39
    locked?: false | true;
40
    lockedForUser?: false | true;
41
    options?: string[];
42
    symbol?: string;
43
    systemColumnType?:
44
      | "AUTO_NUMBER"
45
      | "CREATED_BY"
46
      | "CREATED_DATE"
47
      | "MODIFIED_BY"
48
      | "MODIFIED_DATE";
49
    validation?: false | true;
50
    version?: number;
51
    width?: number;
52
  },
53
) {
54
  const url = new URL(`${auth.baseUrl}/sheets/${sheetId}/columns`);
55

56
  const response = await fetch(url, {
57
    method: "POST",
58
    headers: {
59
      "Content-Type": "application/json",
60
      Authorization: "Bearer " + auth.token,
61
    },
62
    body: JSON.stringify(body),
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70