Delete a custom field

A specific, existing custom field can be deleted by making a DELETE request on the URL for that custom field. Locked custom fields can only be deleted by the user who locked the field. Returns an empty data record.

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
 * Delete a custom field
6
 * A specific, existing custom field can be deleted by making a DELETE request on the URL for that custom field.
7
Locked custom fields can only be deleted by the user who locked the field.
8
Returns an empty data record.
9
 */
10
export async function main(
11
  auth: Asana,
12
  custom_field_gid: string,
13
  opt_pretty: string | undefined,
14
  opt_fields: string | undefined
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/custom_fields/${custom_field_gid}`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "DELETE",
29
    headers: {
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40