Edits history of script submission #23707 for ' Create Task from Template (asana)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Task from Template
     * 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.
     */
    export async function main(
      auth: RT.Asana,
      task_template_gid: string,
      name: string | undefined
    ) {
      const response = await fetch(
        `https://app.asana.com/api/1.0/task_templates/${task_template_gid}/instantiateTask`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({ data: { name: name || undefined } }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 hours ago