0

Get a Member of Enterprise

by
Published Oct 30, 2023

Get a specific member of an enterprise by ID.

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
 * Get a Member of Enterprise
7
 * Get a specific member of an enterprise by ID.
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  idMember: string,
13
  fields: string | undefined,
14
  organization_fields: string | undefined,
15
  board_fields: string | undefined
16
) {
17
  const url = new URL(
18
    `https://api.trello.com/1/enterprises/${id}/members/${idMember}`
19
  );
20
  for (const [k, v] of [
21
    ["fields", fields],
22
    ["organization_fields", organization_fields],
23
    ["board_fields", board_fields],
24
    ["key", auth.key],
25
    ["token", auth.token],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: undefined,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44