0

List Task Templates

by
Published today

List the task templates of a project. Use one with Create Task from Template. Pass `next_page.offset` from a response as `offset` to get the next page.

Script asana Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * List Task Templates
5
 * List the task templates of a project. Use one with Create Task from Template. Pass `next_page.offset` from a response as `offset` to get the next page.
6
 */
7
export async function main(
8
  auth: RT.Asana,
9
  project: string,
10
  opt_fields: string | undefined,
11
  limit: number | undefined,
12
  offset: string | undefined
13
) {
14
  const url = new URL(`https://app.asana.com/api/1.0/task_templates`)
15
  const params = { project, opt_fields, limit: limit ?? 100, offset }
16
  for (const [key, value] of Object.entries(params)) {
17
    if (value != null && value !== "") {
18
      url.searchParams.append(key, String(value))
19
    }
20
  }
21

22
  const response = await fetch(url, {
23
    headers: {
24
      Authorization: `Bearer ${auth.token}`,
25
      Accept: "application/json",
26
    },
27
  })
28

29
  if (!response.ok) {
30
    throw new Error(`${response.status} ${await response.text()}`)
31
  }
32

33
  return await response.json()
34
}
35