0

Find folder for shared link

by
Published Oct 17, 2025

Return the folder represented by a shared link. A shared folder can be represented by a shared link, which can originate within the current enterprise or within another. This endpoint allows an application to retrieve information about a shared folder when only given a shared link.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * Find folder for shared link
7
 * Return the folder represented by a shared link.
8

9
A shared folder can be represented by a shared link,
10
which can originate within the current enterprise or within another.
11

12
This endpoint allows an application to retrieve information about a
13
shared folder when only given a shared link.
14
 */
15
export async function main(
16
  auth: Box,
17
  fields: string | undefined,
18
  if_none_match: string,
19
  boxapi: string,
20
) {
21
  const url = new URL(`https://api.box.com/2.0/shared_items#folders`);
22
  for (const [k, v] of [["fields", fields]]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      "if-none-match": if_none_match,
31
      boxapi: boxapi,
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42