0

Create folder lock

by
Published Oct 17, 2025

Creates a folder lock on a folder, preventing it from being moved and/or deleted. You must be authenticated as the owner or co-owner of the folder to use this endpoint.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Create folder lock
7
 * Creates a folder lock on a folder, preventing it from being moved and/or
8
deleted.
9

10
You must be authenticated as the owner or co-owner of the folder to
11
use this endpoint.
12
 */
13
export async function main(
14
  auth: Box,
15
  body: {
16
    locked_operations?: { move: false | true; delete: false | true };
17
    folder: { type: string; id: string };
18
  },
19
) {
20
  const url = new URL(`https://api.box.com/2.0/folder_locks`);
21

22
  const response = await fetch(url, {
23
    method: "POST",
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