0

Get a list of databases

by
Published Apr 8, 2025

Retrieves a list of databases for the specified branch. A branch can have multiple databases. You can obtain a `project_id` by listing the projects for your Neon account. You can obtain the `branch_id` by listing the project's branches. For related information, see [Manage databases](https://neon.tech/docs/manage/databases/).

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 databases
7
 * Retrieves a list of databases for the specified branch.
8
A branch can have multiple databases.
9
You can obtain a `project_id` by listing the projects for your Neon account.
10
You can obtain the `branch_id` by listing the project's branches.
11
For related information, see [Manage databases](https://neon.tech/docs/manage/databases/).
12

13
 */
14
export async function main(auth: Neondb, project_id: string, branch_id: string) {
15
	const url = new URL(
16
		`https://console.neon.tech/api/v2/projects/${project_id}/branches/${branch_id}/databases`
17
	)
18

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