0

Update web link

by
Published Oct 17, 2025

Updates a web link object.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Update web link
7
 * Updates a web link object.
8
 */
9
export async function main(
10
  auth: Box,
11
  web_link_id: string,
12
  body: {
13
    url?: string;
14
    parent?: { id?: string; user_id?: string } & {};
15
    name?: string;
16
    description?: string;
17
    shared_link?: {
18
      access?: "open" | "company" | "collaborators";
19
      password?: string;
20
      vanity_name?: string;
21
      unshared_at?: string;
22
    };
23
  },
24
) {
25
  const url = new URL(`https://api.box.com/2.0/web_links/${web_link_id}`);
26

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