0

Copy file request

by
Published Oct 17, 2025

Copies an existing file request that is already present on one folder, and applies it to another folder.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Copy file request
7
 * Copies an existing file request that is already present on one folder,
8
and applies it to another folder.
9
 */
10
export async function main(
11
  auth: Box,
12
  file_request_id: string,
13
  body: {
14
    title?: string;
15
    description?: string;
16
    status?: "active" | "inactive";
17
    is_email_required?: false | true;
18
    is_description_required?: false | true;
19
    expires_at?: string;
20
  } & { folder?: { type?: "folder"; id: string } },
21
) {
22
  const url = new URL(
23
    `https://api.box.com/2.0/file_requests/${file_request_id}/copy`,
24
  );
25

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