0

Get a list of roles

by
Published Apr 8, 2025

Retrieves a list of Postgres roles from the specified branch. 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 roles](https://neon.tech/docs/manage/roles/).

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

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

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