0

Search groups by partial query

by
Published Oct 17, 2025

Get search results of groups by partial query provided.

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
 * Search groups by partial query
9
 * Get search results of groups by partial query provided.
10
 */
11
export async function main(
12
	auth: Confluence,
13
	query: string | undefined,
14
	start: string | undefined,
15
	limit: string | undefined,
16
	shouldReturnTotalSize: string | undefined
17
) {
18
	const url = new URL(`https://${auth.domain}/wiki/rest/api/group/picker`)
19
	for (const [k, v] of [
20
		['query', query],
21
		['start', start],
22
		['limit', limit],
23
		['shouldReturnTotalSize', shouldReturnTotalSize]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.json()
41
}
42