0

Find file for shared link

by
Published Oct 17, 2025

Returns the file represented by a shared link. A shared file 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 file when only given a shared link. The `shared_link_permission_options` array field can be returned by requesting it in the `fields` query parameter.

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 file for shared link
7
 * Returns the file represented by a shared link.
8

9
A shared file 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 file when only given a shared link.
14

15
The `shared_link_permission_options` array field can be returned
16
by requesting it in the `fields` query parameter.
17
 */
18
export async function main(
19
  auth: Box,
20
  fields: string | undefined,
21
  if_none_match: string,
22
  boxapi: string,
23
) {
24
  const url = new URL(`https://api.box.com/2.0/shared_items`);
25
  for (const [k, v] of [["fields", fields]]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      "if-none-match": if_none_match,
34
      boxapi: boxapi,
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45