0

Get group memberships for user

by
Published Oct 17, 2025

Returns the groups that a user is a member of. **[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 memberships for user
9
 * Returns the groups that a user is a member of.
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(
15
	auth: Confluence,
16
	accountId: string | undefined,
17
	start: string | undefined,
18
	limit: string | undefined
19
) {
20
	const url = new URL(`https://${auth.domain}/wiki/rest/api/user/memberof`)
21
	for (const [k, v] of [
22
		['accountId', accountId],
23
		['start', start],
24
		['limit', limit]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30
	const response = await fetch(url, {
31
		method: 'GET',
32
		headers: {
33
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
34
		},
35
		body: undefined
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43