0

Get a list of branch endpoints

by
Published Apr 8, 2025

Retrieves a list of compute endpoints for the specified branch. Neon permits only one read-write compute endpoint per branch. A branch can have multiple read-only compute endpoints. 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.

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 branch endpoints
7
 * Retrieves a list of compute endpoints for the specified branch.
8
Neon permits only one read-write compute endpoint per branch.
9
A branch can have multiple read-only compute endpoints.
10
You can obtain a `project_id` by listing the projects for your Neon account.
11
You can obtain the `branch_id` by listing the project's branches.
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}/endpoints`
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