type Asana = {
token: string;
};
/**
* Duplicate a project
* Creates and returns a job that will asynchronously handle the duplication.
*/
export async function main(
auth: Asana,
project_gid: string,
opt_pretty: string | undefined,
opt_fields: string | undefined,
body: {
data?: {
include?:
| "members"
| "notes"
| "forms"
| "task_notes"
| "task_assignee"
| "task_subtasks"
| "task_attachments"
| "task_dates"
| "task_dependencies"
| "task_followers"
| "task_tags"
| "task_projects";
name: string;
schedule_dates?: {
due_on?: string;
should_skip_weekends: boolean;
start_on?: string;
[k: string]: unknown;
};
team?: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://app.asana.com/api/1.0/projects/${project_gid}/duplicate`
);
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: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 202 days ago