Edits history of script submission #20437 for ' Add Columns (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Add Columns
     * 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.
     */
    export async function main(
      auth: Smartsheet,
      sheetId: string,
      body: {
        title?: string;
        type?:
          | "ABSTRACT_DATETIME"
          | "CHECKBOX"
          | "CONTACT_LIST"
          | "DATE"
          | "DATETIME"
          | "DURATION"
          | "MULTI_CONTACT_LIST"
          | "MULTI_PICKLIST"
          | "PICKLIST"
          | "PREDECESSOR"
          | "TEXT_NUMBER";
        formula?: string;
        hidden?: false | true;
        index?: number;
        autoNumberFormat?: {
          fill?: string;
          prefix?: string;
          startingNumber?: number;
          suffix?: string;
        };
        contactOptions?: { email?: string; name?: string };
        description?: string;
        format?: string;
        locked?: false | true;
        lockedForUser?: false | true;
        options?: string[];
        symbol?: string;
        systemColumnType?:
          | "AUTO_NUMBER"
          | "CREATED_BY"
          | "CREATED_DATE"
          | "MODIFIED_BY"
          | "MODIFIED_DATE";
        validation?: false | true;
        version?: number;
        width?: number;
      },
    ) {
      const url = new URL(`${auth.baseUrl}/sheets/${sheetId}/columns`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago