0

Get PendingOrganizations of an Enterprise

by
Published Oct 30, 2023

Get the Workspaces that are pending for the 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 PendingOrganizations of an Enterprise
7
 * Get the Workspaces that are pending for the enterprise by ID.
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  activeSince: string | undefined,
13
  inactiveSince: string | undefined
14
) {
15
  const url = new URL(
16
    `https://api.trello.com/1/enterprises/${id}/pendingOrganizations`
17
  );
18
  for (const [k, v] of [
19
    ["activeSince", activeSince],
20
    ["inactiveSince", inactiveSince],
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: "GET",
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.json();
40
}
41