0

Search users

by
Published Oct 17, 2025

Searches for users using user-specific queries from the [Confluence Query Language (CQL)](https://developer.

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 users
9
 * Searches for users using user-specific queries from the
10
[Confluence Query Language (CQL)](https://developer.
11
 */
12
export async function main(
13
	auth: Confluence,
14
	cql: string | undefined,
15
	start: string | undefined,
16
	limit: string | undefined,
17
	expand: string | undefined,
18
	sitePermissionTypeFilter: 'all' | 'externalCollaborator' | 'none' | undefined
19
) {
20
	const url = new URL(`https://${auth.domain}/wiki/rest/api/search/user`)
21
	for (const [k, v] of [
22
		['cql', cql],
23
		['start', start],
24
		['limit', limit],
25
		['expand', expand],
26
		['sitePermissionTypeFilter', sitePermissionTypeFilter]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'GET',
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.json()
44
}
45