Edits history of script submission #14544 for ' Update collaboration (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Update collaboration
     * Updates a collaboration.
    Can be used to change the owner of an item, or to
    accept collaboration invites.
     */
    export async function main(
      auth: Box,
      collaboration_id: string,
      body: {
        role:
          | "editor"
          | "viewer"
          | "previewer"
          | "uploader"
          | "previewer uploader"
          | "viewer uploader"
          | "co-owner"
          | "owner";
        status?: "pending" | "accepted" | "rejected";
        expires_at?: string;
        can_view_path?: false | true;
      },
    ) {
      const url = new URL(
        `https://api.box.com/2.0/collaborations/${collaboration_id}`,
      );
    
      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