1 | |
2 | type Clerk = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Get a list of organizations for an instance |
7 | * This request returns the list of organizations for an instance. |
8 | Results can be paginated using the optional `limit` and `offset` query parameters. |
9 | The organizations are ordered by descending creation date. |
10 | Most recent organizations will be returned first. |
11 | */ |
12 | export async function main( |
13 | auth: Clerk, |
14 | limit: string | undefined, |
15 | offset: string | undefined, |
16 | include_members_count: string | undefined, |
17 | query: string | undefined, |
18 | order_by: string | undefined, |
19 | ) { |
20 | const url = new URL(`https://api.clerk.com/v1/organizations`); |
21 | for (const [k, v] of [ |
22 | ["limit", limit], |
23 | ["offset", offset], |
24 | ["include_members_count", include_members_count], |
25 | ["query", query], |
26 | ["order_by", order_by], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "GET", |
34 | headers: { |
35 | Authorization: "Bearer " + auth.apiKey, |
36 | }, |
37 | body: undefined, |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|