0

Get a list of all domains of an organization.

by
Published Apr 8, 2025

Get a list of all domains of an organization.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Get a list of all domains of an organization.
7
 * Get a list of all domains of an organization.
8
 */
9
export async function main(
10
  auth: Clerk,
11
  organization_id: string,
12
  limit: string | undefined,
13
  offset: string | undefined,
14
  verified: string | undefined,
15
  enrollment_mode: string | undefined,
16
) {
17
  const url = new URL(
18
    `https://api.clerk.com/v1/organizations/${organization_id}/domains`,
19
  );
20
  for (const [k, v] of [
21
    ["limit", limit],
22
    ["offset", offset],
23
    ["verified", verified],
24
    ["enrollment_mode", enrollment_mode],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.apiKey,
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