0

Get a list of shared projects

by
Published Apr 8, 2025

Retrieves a list of shared projects for the Neon account. A project is the top-level object in the Neon object hierarchy. For more information, see [Manage projects](https://neon.tech/docs/manage/projects/).

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Get a list of shared projects
7
 * Retrieves a list of shared projects for the Neon account.
8
A project is the top-level object in the Neon object hierarchy.
9
For more information, see [Manage projects](https://neon.tech/docs/manage/projects/).
10

11
 */
12
export async function main(
13
	auth: Neondb,
14
	cursor: string | undefined,
15
	limit: string | undefined,
16
	search: string | undefined
17
) {
18
	const url = new URL(`https://console.neon.tech/api/v2/projects/shared`)
19
	for (const [k, v] of [
20
		['cursor', cursor],
21
		['limit', limit],
22
		['search', search]
23
	]) {
24
		if (v !== undefined && v !== '' && k !== undefined) {
25
			url.searchParams.append(k, v)
26
		}
27
	}
28
	const response = await fetch(url, {
29
		method: 'GET',
30
		headers: {
31
			Authorization: 'Bearer ' + auth.apiKey
32
		},
33
		body: undefined
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41