0

Create Task from Template

by
Published today

Create a task from a task template (see List Task Templates). Asana creates it asynchronously: the response is a job whose `new_task` holds the task's gid.

Script asana Verified

The script

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

3
/**
4
 * Create Task from Template
5
 * Create a task from a task template (see List Task Templates). Asana creates it asynchronously: the response is a job whose `new_task` holds the task's gid.
6
 */
7
export async function main(
8
  auth: RT.Asana,
9
  task_template_gid: string,
10
  name: string | undefined
11
) {
12
  const response = await fetch(
13
    `https://app.asana.com/api/1.0/task_templates/${task_template_gid}/instantiateTask`,
14
    {
15
      method: "POST",
16
      headers: {
17
        Authorization: `Bearer ${auth.token}`,
18
        "Content-Type": "application/json",
19
        Accept: "application/json",
20
      },
21
      body: JSON.stringify({ data: { name: name || undefined } }),
22
    }
23
  )
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  return await response.json()
30
}
31