1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Create a project brief |
6 | * Creates a new project brief. |
7 |
|
8 | Returns the full record of the newly created project brief. |
9 | */ |
10 | export async function main( |
11 | auth: Asana, |
12 | project_gid: string, |
13 | opt_pretty: string | undefined, |
14 | opt_fields: string | undefined, |
15 | body: { |
16 | data?: (({ gid?: string; resource_type?: string; [k: string]: unknown } & { |
17 | [k: string]: unknown; |
18 | }) & { html_text?: string; title?: string; [k: string]: unknown }) & { |
19 | text?: string; |
20 | [k: string]: unknown; |
21 | }; |
22 | [k: string]: unknown; |
23 | } |
24 | ) { |
25 | const url = new URL( |
26 | `https://app.asana.com/api/1.0/projects/${project_gid}/project_briefs` |
27 | ); |
28 | for (const [k, v] of [ |
29 | ["opt_pretty", opt_pretty], |
30 | ["opt_fields", opt_fields], |
31 | ]) { |
32 | if (v !== undefined && v !== "") { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "POST", |
38 | headers: { |
39 | "Content-Type": "application/json", |
40 | Authorization: "Bearer " + auth.token, |
41 | }, |
42 | body: JSON.stringify(body), |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|