0

Get group

by
Published Oct 17, 2025

Returns a user group for a given group id. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to access the Confluence site ('Can use' global permission).

Script confluence Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Confluence = {
3
	email: string
4
	apiToken: string
5
	domain: string
6
}
7
/**
8
 * Get group
9
 * Returns a user group for a given group id.
10

11
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
12
Permission to access the Confluence site ('Can use' global permission).
13
 */
14
export async function main(auth: Confluence, id: string | undefined) {
15
	const url = new URL(`https://${auth.domain}/wiki/rest/api/group/by-id`)
16
	for (const [k, v] of [['id', id]]) {
17
		if (v !== undefined && v !== '' && k !== undefined) {
18
			url.searchParams.append(k, v)
19
		}
20
	}
21
	const response = await fetch(url, {
22
		method: 'GET',
23
		headers: {
24
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
25
		},
26
		body: undefined
27
	})
28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32
	return await response.json()
33
}
34