0

Get a list of organization invitations for the current instance

by
Published Apr 8, 2025

This request returns the list of organization invitations for the instance.

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 organization invitations for the current instance
7
 * This request returns the list of organization invitations for the instance.
8
 */
9
export async function main(
10
  auth: Clerk,
11
  limit: string | undefined,
12
  offset: string | undefined,
13
  order_by: string | undefined,
14
  status: "pending" | "accepted" | "revoked" | undefined,
15
  query: string | undefined,
16
) {
17
  const url = new URL(`https://api.clerk.com/v1/organization_invitations`);
18
  for (const [k, v] of [
19
    ["limit", limit],
20
    ["offset", offset],
21
    ["order_by", order_by],
22
    ["status", status],
23
    ["query", query],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.apiKey,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42