Edits history of script submission #14533 for ' Restore file version (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Restore file version
     * Restores a specific version of a file after it was deleted.
    Don't use this endpoint to restore Box Notes,
    as it works with file formats such as PDF, DOC,
    PPTX or similar.
     */
    export async function main(
      auth: Box,
      file_id: string,
      file_version_id: string,
      body: { trashed_at?: string },
    ) {
      const url = new URL(
        `https://api.box.com/2.0/files/${file_id}/versions/${file_version_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