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

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Update Dashboard Share
     * Updates the access level of a user or group for the specified dashboard.
     */
    export async function main(
      auth: Smartsheet,
      sightId: string,
      shareId: string,
      accessApiLevel: string | undefined,
      body: {
        accessLevel?:
          | "ADMIN"
          | "COMMENTER"
          | "EDITOR"
          | "EDITOR_SHARE"
          | "OWNER"
          | "VIEWER";
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/sights/${sightId}/shares/${shareId}`,
      );
      for (const [k, v] of [["accessApiLevel", accessApiLevel]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        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