0

Revoke a pending organization invitation

by
Published Apr 8, 2025

Use this request to revoke a previously issued organization invitation. Revoking an organization invitation makes it invalid; the invited user will no longer be able to join the organization with the revoked invitation. Only organization invitations with "pending" status can be revoked. The request accepts the `requesting_user_id` parameter to specify the user which revokes the invitation. Only users with "admin" role can revoke invitations.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Revoke a pending organization invitation
7
 * Use this request to revoke a previously issued organization invitation.
8
Revoking an organization invitation makes it invalid; the invited user will no longer be able to join the organization with the revoked invitation.
9
Only organization invitations with "pending" status can be revoked.
10
The request accepts the `requesting_user_id` parameter to specify the user which revokes the invitation.
11
Only users with "admin" role can revoke invitations.
12
 */
13
export async function main(
14
  auth: Clerk,
15
  organization_id: string,
16
  invitation_id: string,
17
  body: { requesting_user_id?: string },
18
) {
19
  const url = new URL(
20
    `https://api.clerk.com/v1/organizations/${organization_id}/invitations/${invitation_id}/revoke`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.apiKey,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37