0

Check content permissions

by
Published Oct 17, 2025

Check if a user or a group can perform an operation to the specified content.

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
 * Check content permissions
9
 * Check if a user or a group can perform an operation to the specified content.
10
 */
11
export async function main(
12
	auth: Confluence,
13
	id: string,
14
	body: {
15
		subject: { type: 'user' | 'group'; identifier: string }
16
		operation: 'read' | 'update' | 'delete'
17
	}
18
) {
19
	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/permission/check`)
20

21
	const response = await fetch(url, {
22
		method: 'POST',
23
		headers: {
24
			'Content-Type': 'application/json',
25
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
26
		},
27
		body: JSON.stringify(body)
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35