Edits history of script submission #20547 for ' Share Sheet (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Share Sheet
     * Shares a sheet with the specified users and groups.
     */
    export async function main(
      auth: Smartsheet,
      sheetId: string,
      accessApiLevel: string | undefined,
      sendEmail: string | undefined,
      body:
        | {
            id?: string;
            groupId?: number;
            userId?: number;
            type?: string;
            accessLevel?:
              | "ADMIN"
              | "COMMENTER"
              | "EDITOR"
              | "EDITOR_SHARE"
              | "OWNER"
              | "VIEWER";
            ccMe?: false | true;
            createdAt?: string | number;
            email?: string;
            message?: string;
            modifiedAt?: string | number;
            name?: string;
            scope?: string;
            subject?: string;
          }
        | {
            id?: string;
            groupId?: number;
            userId?: number;
            type?: string;
            accessLevel?:
              | "ADMIN"
              | "COMMENTER"
              | "EDITOR"
              | "EDITOR_SHARE"
              | "OWNER"
              | "VIEWER";
            ccMe?: false | true;
            createdAt?: string | number;
            email?: string;
            message?: string;
            modifiedAt?: string | number;
            name?: string;
            scope?: string;
            subject?: string;
          }[],
    ) {
      const url = new URL(`${auth.baseUrl}/sheets/${sheetId}/shares`);
      for (const [k, v] of [
        ["accessApiLevel", accessApiLevel],
        ["sendEmail", sendEmail],
      ]) {
        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