0

Update a Custom Field definition

by
Published Oct 30, 2023

Update a Custom Field definition.

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
 * Update a Custom Field definition
7
 * Update a Custom Field definition.
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  body: {
13
    name?: string;
14
    pos?: ("top" | "bottom") | number;
15
    "display/cardFront"?: boolean;
16
    [k: string]: unknown;
17
  }
18
) {
19
  const url = new URL(`https://api.trello.com/1/customFields/${id}`);
20
  for (const [k, v] of [
21
    ["key", auth.key],
22
    ["token", auth.token],
23
  ]) {
24
    if (v !== undefined && v !== "") {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "PUT",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: undefined,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42