0

Delete Option of Custom Field dropdown

by
Published Oct 30, 2023

Delete an option from a Custom Field dropdown.

Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Delete Option of Custom Field dropdown
7
 * Delete an option from a Custom Field dropdown.
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  idCustomFieldOption: string
13
) {
14
  const url = new URL(
15
    `https://api.trello.com/1/customFields/${id}/options/${idCustomFieldOption}`
16
  );
17
  for (const [k, v] of [
18
    ["key", auth.key],
19
    ["token", auth.token],
20
  ]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "DELETE",
27
    headers: {
28
      Authorization: undefined,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.text();
37
}
38