0

List Public Templates

by
Published Oct 17, 2025

Gets a list of public templates that the user has access to.

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
 * List Public Templates
8
 * Gets a list of public templates that the user has access to.
9
 */
10
export async function main(
11
  auth: Smartsheet,
12
  accessApiLevel: string | undefined,
13
  includeAll: string | undefined,
14
  level: "0" | "1" | undefined,
15
  page: string | undefined,
16
  pageSize: string | undefined,
17
) {
18
  const url = new URL(`${auth.baseUrl}/templates/public`);
19
  for (const [k, v] of [
20
    ["accessApiLevel", accessApiLevel],
21
    ["includeAll", includeAll],
22
    ["level", level],
23
    ["page", page],
24
    ["pageSize", pageSize],
25
  ]) {
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
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43