1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Update a project brief |
6 | * An existing project brief can be updated by making a PUT request on the URL for |
7 | that project brief. Only the fields provided in the `data` block will be updated; |
8 | any unspecified fields will remain unchanged. |
9 |
|
10 | Returns the complete updated project brief record. |
11 | */ |
12 | export async function main( |
13 | auth: Asana, |
14 | project_brief_gid: string, |
15 | opt_pretty: string | undefined, |
16 | opt_fields: string | undefined, |
17 | body: { |
18 | data?: (({ gid?: string; resource_type?: string; [k: string]: unknown } & { |
19 | [k: string]: unknown; |
20 | }) & { html_text?: string; title?: string; [k: string]: unknown }) & { |
21 | text?: string; |
22 | [k: string]: unknown; |
23 | }; |
24 | [k: string]: unknown; |
25 | } |
26 | ) { |
27 | const url = new URL( |
28 | `https://app.asana.com/api/1.0/project_briefs/${project_brief_gid}` |
29 | ); |
30 | for (const [k, v] of [ |
31 | ["opt_pretty", opt_pretty], |
32 | ["opt_fields", opt_fields], |
33 | ]) { |
34 | if (v !== undefined && v !== "") { |
35 | url.searchParams.append(k, v); |
36 | } |
37 | } |
38 | const response = await fetch(url, { |
39 | method: "PUT", |
40 | headers: { |
41 | "Content-Type": "application/json", |
42 | Authorization: "Bearer " + auth.token, |
43 | }, |
44 | body: JSON.stringify(body), |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|