0

Get signupUrl for Enterprise

by
Published Oct 30, 2023

Get the signup URL for an enterprise.

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