Get multiple project templates

Returns the compact project template records for all project templates in the given team or workspace.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get multiple project templates
6
 * Returns the compact project template records for all project templates in the given team or workspace.
7
 */
8
export async function main(
9
  auth: Asana,
10
  opt_pretty: string | undefined,
11
  opt_fields: string | undefined,
12
  workspace: string | undefined,
13
  team: string | undefined,
14
  limit: string | undefined,
15
  offset: string | undefined
16
) {
17
  const url = new URL(`https://app.asana.com/api/1.0/project_templates`);
18
  for (const [k, v] of [
19
    ["opt_pretty", opt_pretty],
20
    ["opt_fields", opt_fields],
21
    ["workspace", workspace],
22
    ["team", team],
23
    ["limit", limit],
24
    ["offset", offset],
25
  ]) {
26
    if (v !== undefined && v !== "") {
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