0

Update an organization

by
Published Apr 8, 2025

Updates an existing organization

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Update an organization
7
 * Updates an existing organization
8
 */
9
export async function main(
10
  auth: Clerk,
11
  organization_id: string,
12
  body: {
13
    public_metadata?: {};
14
    private_metadata?: {};
15
    name?: string;
16
    slug?: string;
17
    max_allowed_memberships?: number;
18
    admin_delete_enabled?: false | true;
19
    created_at?: string;
20
  },
21
) {
22
  const url = new URL(
23
    `https://api.clerk.com/v1/organizations/${organization_id}`,
24
  );
25

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