0

Get a list of projects

by
Published Apr 8, 2025

Retrieves a list of 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 projects
7
 * Retrieves a list of 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
	org_id: string | undefined
18
) {
19
	const url = new URL(`https://console.neon.tech/api/v2/projects`)
20
	for (const [k, v] of [
21
		['cursor', cursor],
22
		['limit', limit],
23
		['search', search],
24
		['org_id', org_id]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30
	const response = await fetch(url, {
31
		method: 'GET',
32
		headers: {
33
			Authorization: 'Bearer ' + auth.apiKey
34
		},
35
		body: undefined
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43