0

Delete an organization

by
Published Apr 8, 2025

Deletes the given organization. Please note that deleting an organization will also delete all memberships and invitations. This is not reversible.

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Delete an organization
7
 * Deletes the given organization.
8
Please note that deleting an organization will also delete all memberships and invitations.
9
This is not reversible.
10
 */
11
export async function main(auth: Clerk, organization_id: string) {
12
  const url = new URL(
13
    `https://api.clerk.com/v1/organizations/${organization_id}`,
14
  );
15

16
  const response = await fetch(url, {
17
    method: "DELETE",
18
    headers: {
19
      Authorization: "Bearer " + auth.apiKey,
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29