type Asana = {
token: string;
};
/**
* Instantiate a project from a project template
* Creates and returns a job that will asynchronously handle the project instantiation.
*/
export async function main(
auth: Asana,
project_template_gid: string,
opt_pretty: string | undefined,
opt_fields: string | undefined,
body: {
data?: {
is_strict?: boolean;
name: string;
public: boolean;
requested_dates?: {
gid?: string;
value?: string;
[k: string]: unknown;
}[];
team?: string;
workspace?: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://app.asana.com/api/1.0/project_templates/${project_template_gid}/instantiateProject`
);
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 443 days ago