type Asana = {
token: string;
};
/**
* Delete a task
* A specific, existing task can be deleted by making a DELETE request on
the URL for that task. Deleted tasks go into the “trash” of the user
making the delete request. Tasks can be recovered from the trash within a
period of 30 days; afterward they are completely removed from the system.
Returns an empty data record.
*/
export async function main(
auth: Asana,
task_gid: string,
opt_pretty: string | undefined,
opt_fields: string | undefined
) {
const url = new URL(`https://app.asana.com/api/1.0/tasks/${task_gid}`);
for (const [k, v] of [
["opt_pretty", opt_pretty],
["opt_fields", opt_fields],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 390 days ago