0

Create Group

by
Published Sep 27, 2024

Creates a new group for the organization or user.

Script turso Verified

The script

Submitted by hugo697 Bun
Verified 621 days ago
1
//native
2
type Turso = {
3
	apiToken: string
4
}
5

6
export async function main(
7
	resource: Turso,
8
	organizationSlug: string,
9
	groupProperties: {
10
		name: string
11
		location: string
12
	}
13
) {
14
	const endpoint = `https://api.turso.tech/v1/organizations/${organizationSlug}/groups`
15

16
	const response = await fetch(endpoint, {
17
		method: 'POST',
18
		headers: {
19
			Authorization: `Bearer ${resource.apiToken}`,
20
			'Content-Type': 'application/json'
21
		},
22
		body: JSON.stringify(groupProperties)
23
	})
24

25
	if (!response.ok) {
26
		throw new Error(`HTTP error! status: ${response.status}`)
27
	}
28

29
	const data = await response.json()
30

31
	return data.group
32
}
33