0

Get Report

by
Published Oct 17, 2025

Gets a report based on the specified ID

Script smartsheet Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Smartsheet = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Get Report
8
 * Gets a report based on the specified ID
9
 */
10
export async function main(
11
  auth: Smartsheet,
12
  reportId: string,
13
  accessApiLevel: string | undefined,
14
  include:
15
    | "attachments"
16
    | "discussions"
17
    | "proofs"
18
    | "format"
19
    | "objectValue"
20
    | "scope"
21
    | "source"
22
    | "sourceSheets"
23
    | undefined,
24
  exclude: "linkInFromCellDetails" | "linksOutToCellsDetails" | undefined,
25
  pageSize: string | undefined,
26
  page: string | undefined,
27
  level: string | undefined,
28
) {
29
  const url = new URL(`${auth.baseUrl}/reports/${reportId}`);
30
  for (const [k, v] of [
31
    ["accessApiLevel", accessApiLevel],
32
    ["include", include],
33
    ["exclude", exclude],
34
    ["pageSize", pageSize],
35
    ["page", page],
36
    ["level", level],
37
  ]) {
38
    if (v !== undefined && v !== "" && k !== undefined) {
39
      url.searchParams.append(k, v);
40
    }
41
  }
42
  const response = await fetch(url, {
43
    method: "GET",
44
    headers: {
45
      Authorization: "Bearer " + auth.token,
46
    },
47
    body: undefined,
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55