0

Get content restriction status for user

by
Published Oct 17, 2025

Returns whether the specified content restriction applies to a user.

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 content restriction status for user
9
 * Returns whether the specified content restriction applies to a user.
10
 */
11
export async function main(
12
	auth: Confluence,
13
	id: string,
14
	operationKey: string,
15
	key: string | undefined,
16
	username: string | undefined,
17
	accountId: string | undefined
18
) {
19
	const url = new URL(
20
		`https://${auth.domain}/wiki/rest/api/content/${id}/restriction/byOperation/${operationKey}/user`
21
	)
22
	for (const [k, v] of [
23
		['key', key],
24
		['username', username],
25
		['accountId', accountId]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.text()
43
}
44