Edits history of script submission #20546 for ' Share Dashboard (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Share Dashboard
     * Shares a dashboard with the specified users and groups.
     */
    export async function main(
      auth: Smartsheet,
      sightId: 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;
      },
    ) {
      const url = new URL(`${auth.baseUrl}/sights/${sightId}/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