Edits history of script submission #20450 for ' Create Sheet in Folder (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Create Sheet in Folder
     * Creates a sheet from scratch or from the specified template in the specified folder.
    
     */
    export async function main(
      auth: Smartsheet,
      folderId: string,
      include:
        | "attachments"
        | "cellLinks"
        | "data"
        | "discussions"
        | "filters"
        | "forms"
        | "ruleRecipients"
        | "rules"
        | undefined,
      body:
        | {
            columns?: {
              autoNumberFormat?: {
                fill?: string;
                prefix?: string;
                startingNumber?: number;
                suffix?: string;
              };
              contactOptions?: { email?: string; name?: string }[];
              options?: string[];
              primary?: false | true;
              symbol?: string;
              systemColumnType?:
                | "AUTO_NUMBER"
                | "CREATED_BY"
                | "CREATED_DATE"
                | "MODIFIED_BY"
                | "MODIFIED_DATE";
              title?: string;
              type?:
                | "ABSTRACT_DATETIME"
                | "CHECKBOX"
                | "CONTACT_LIST"
                | "DATE"
                | "DATETIME"
                | "DURATION"
                | "MULTI_CONTACT_LIST"
                | "MULTI_PICKLIST"
                | "PICKLIST"
                | "PREDECESSOR"
                | "TEXT_NUMBER";
              width?: number;
            }[];
            name?: string;
          }
        | { fromId?: number; name?: string },
    ) {
      const url = new URL(`${auth.baseUrl}/folders/${folderId}/sheets`);
      for (const [k, v] of [["include", include]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      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