0

Get role details

by
Published Apr 8, 2025

Retrieves details about the specified role. 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. You can obtain the `role_name` by listing the roles for a branch. In Neon, the terms "role" and "user" are synonymous. 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 role details
7
 * Retrieves details about the specified role.
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
You can obtain the `role_name` by listing the roles for a branch.
11
In Neon, the terms "role" and "user" are synonymous.
12
For related information, see [Manage roles](https://neon.tech/docs/manage/roles/).
13

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

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