//native
/**
* Create Subtask
* Create a subtask under an existing task. Subtasks are not added to the parent's projects unless `projects` is set. Dates: `due_on`/`start_on` as YYYY-MM-DD, or `due_at` as an ISO 8601 date-time.
*/
export async function main(
auth: RT.Asana,
task_gid: string,
name: string,
notes: string | undefined,
html_notes: string | undefined,
assignee: string | undefined,
due_on: string | undefined,
due_at: string | undefined,
start_on: string | undefined,
projects: string[] | undefined,
tags: string[] | undefined,
followers: string[] | undefined,
completed: boolean | undefined,
custom_fields: { [key: string]: any } | undefined
) {
const data = {
name,
notes: notes || undefined,
html_notes: html_notes || undefined,
assignee: assignee || undefined,
due_on: due_on || undefined,
due_at: due_at || undefined,
start_on: start_on || undefined,
projects: projects?.length ? projects : undefined,
tags: tags?.length ? tags : undefined,
followers: followers?.length ? followers : undefined,
completed: completed || undefined,
custom_fields:
custom_fields && Object.keys(custom_fields).length
? custom_fields
: undefined,
}
const response = await fetch(
`https://app.asana.com/api/1.0/tasks/${task_gid}/subtasks`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ data }),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 3 hours ago