Create a project brief

Creates a new project brief. Returns the full record of the newly created project brief.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
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