0

Remove file version

by
Published Oct 17, 2025

Move a file version to the trash. Versions are only tracked for Box users with premium accounts.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Remove file version
7
 * Move a file version to the trash.
8

9
Versions are only tracked for Box users with premium accounts.
10
 */
11
export async function main(
12
  auth: Box,
13
  file_id: string,
14
  file_version_id: string,
15
  if_match: string,
16
) {
17
  const url = new URL(
18
    `https://api.box.com/2.0/files/${file_id}/versions/${file_version_id}`,
19
  );
20

21
  const response = await fetch(url, {
22
    method: "DELETE",
23
    headers: {
24
      "if-match": if_match,
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35