0
Remove a custom field from a project
One script reply has been approved by the moderators Verified

Removes a custom field setting from a project.

Created by hugo697 449 days ago Viewed 12007 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 449 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Remove a custom field from a project
6
 * Removes a custom field setting from a project.
7
 */
8
export async function main(
9
  auth: Asana,
10
  project_gid: string,
11
  opt_pretty: string | undefined,
12
  body: {
13
    data?: { custom_field: string; [k: string]: unknown };
14
    [k: string]: unknown;
15
  }
16
) {
17
  const url = new URL(
18
    `https://app.asana.com/api/1.0/projects/${project_gid}/removeCustomFieldSetting`
19
  );
20
  for (const [k, v] of [["opt_pretty", opt_pretty]]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39