Edits history of script submission #17283 for ' Copy board (miro)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Miro = {
      token: string;
    };
    /**
     * Copy board
     * Creates a copy of an existing board. You can also update the name, description, sharing policy, and permissions policy for the new board in the request body.Required scope boards:write Rate limiting Level 4
     */
    export async function main(
      auth: Miro,
      copy_from: string | undefined,
      body: {
        description?: string;
        name?: string;
        policy?: {
          permissionsPolicy?: {
            collaborationToolsStartAccess?:
              | "all_editors"
              | "board_owners_and_coowners";
            copyAccess?: "anyone" | "team_members" | "team_editors" | "board_owner";
            sharingAccess?:
              | "team_members_with_editing_rights"
              | "owner_and_coowners";
          };
          sharingPolicy?: {
            access?: "private" | "view" | "edit" | "comment";
            inviteToAccountAndBoardLinkAccess?:
              | "viewer"
              | "commenter"
              | "editor"
              | "no_access";
            organizationAccess?: "private" | "view" | "edit" | "comment";
            teamAccess?: "private" | "view" | "edit" | "comment";
          };
        };
        teamId?: string;
      },
    ) {
      const url = new URL(`https://api.miro.com//v2/boards`);
      for (const [k, v] of [["copy_from", copy_from]]) {
        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