0

Update an Organization's Members

by
Published Oct 30, 2023
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 an Organization's Members
7
 *
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  email: string | undefined,
13
  fullName: string | undefined,
14
  type: "admin" | "normal" | undefined
15
) {
16
  const url = new URL(`https://api.trello.com/1/organizations/${id}/members`);
17
  for (const [k, v] of [
18
    ["email", email],
19
    ["fullName", fullName],
20
    ["type", type],
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
      Authorization: undefined,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.text();
40
}
41