0

List recently accessed items

by
Published Oct 17, 2025

Returns information about the recent items accessed by a user, either in the last 90 days or up to the last 1000 items accessed.

Script box Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Box = {
3
  token: string;
4
};
5
/**
6
 * List recently accessed items
7
 * Returns information about the recent items accessed
8
by a user, either in the last 90 days or up to the last
9
1000 items accessed.
10
 */
11
export async function main(
12
  auth: Box,
13
  fields: string | undefined,
14
  limit: string | undefined,
15
  marker: string | undefined,
16
) {
17
  const url = new URL(`https://api.box.com/2.0/recent_items`);
18
  for (const [k, v] of [
19
    ["fields", fields],
20
    ["limit", limit],
21
    ["marker", marker],
22
  ]) {
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
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: undefined,
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