0

Restore file version

by
Published Oct 17, 2025

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.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Restore file version
7
 * Restores a specific version of a file after it was deleted.
8
Don't use this endpoint to restore Box Notes,
9
as it works with file formats such as PDF, DOC,
10
PPTX or similar.
11
 */
12
export async function main(
13
  auth: Box,
14
  file_id: string,
15
  file_version_id: string,
16
  body: { trashed_at?: string },
17
) {
18
  const url = new URL(
19
    `https://api.box.com/2.0/files/${file_id}/versions/${file_version_id}`,
20
  );
21

22
  const response = await fetch(url, {
23
    method: "PUT",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36