0

Get a list of organization invitations

by
Published Apr 8, 2025

This request returns the list of organization invitations. Results can be paginated using the optional `limit` and `offset` query parameters. You can filter them by providing the 'status' query parameter, that accepts multiple values. The organization invitations are ordered by descending creation date. Most recent invitations will be returned first. Any invitations created as a result of an Organization Domain are not included in the results.

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
7
 * This request returns the list of organization invitations.
8
Results can be paginated using the optional `limit` and `offset` query parameters.
9
You can filter them by providing the 'status' query parameter, that accepts multiple values.
10
The organization invitations are ordered by descending creation date.
11
Most recent invitations will be returned first.
12
Any invitations created as a result of an Organization Domain are not included in the results.
13
 */
14
export async function main(
15
  auth: Clerk,
16
  organization_id: string,
17
  limit: string | undefined,
18
  offset: string | undefined,
19
  status: "pending" | "accepted" | "revoked" | undefined,
20
) {
21
  const url = new URL(
22
    `https://api.clerk.com/v1/organizations/${organization_id}/invitations`,
23
  );
24
  for (const [k, v] of [
25
    ["limit", limit],
26
    ["offset", offset],
27
    ["status", status],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.apiKey,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46