0

Remove member from group using group id

by
Published Oct 17, 2025

Remove user as a member from a group. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: User must be a site admin.

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
 * Remove member from group using group id
9
 * Remove user as a member from a group.
10

11
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
12
User must be a site admin.
13
 */
14
export async function main(
15
	auth: Confluence,
16
	groupId: string | undefined,
17
	key: string | undefined,
18
	username: string | undefined,
19
	accountId: string | undefined
20
) {
21
	const url = new URL(`https://${auth.domain}/wiki/rest/api/group/userByGroupId`)
22
	for (const [k, v] of [
23
		['groupId', groupId],
24
		['key', key],
25
		['username', username],
26
		['accountId', accountId]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'DELETE',
34
		headers: {
35
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
36
		},
37
		body: undefined
38
	})
39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`${response.status} ${text}`)
42
	}
43
	return await response.text()
44
}
45