0

Get content watch status

by
Published Oct 17, 2025

Returns whether a user is watching a piece of content. Choose the user by doing one of the following: - Specify a user via a query parameter: Use the `accountId` to identify the user. - Do not specify a user: The currently logged-in user will be used. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: 'Confluence Administrator' global permission if specifying a user, otherwise permission to access the Confluence site ('Can use' global permission).

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 watch status
9
 * Returns whether a user is watching a piece of content. Choose the user by
10
doing one of the following:
11

12
- Specify a user via a query parameter: Use the `accountId` to identify the user.
13
- Do not specify a user: The currently logged-in user will be used.
14

15
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
16
'Confluence Administrator' global permission if specifying a user, otherwise
17
permission to access the Confluence site ('Can use' global permission).
18
 */
19
export async function main(
20
	auth: Confluence,
21
	contentId: string,
22
	key: string | undefined,
23
	username: string | undefined,
24
	accountId: string | undefined
25
) {
26
	const url = new URL(`https://${auth.domain}/wiki/rest/api/user/watch/content/${contentId}`)
27
	for (const [k, v] of [
28
		['key', key],
29
		['username', username],
30
		['accountId', accountId]
31
	]) {
32
		if (v !== undefined && v !== '' && k !== undefined) {
33
			url.searchParams.append(k, v)
34
		}
35
	}
36
	const response = await fetch(url, {
37
		method: 'GET',
38
		headers: {
39
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
40
		},
41
		body: undefined
42
	})
43
	if (!response.ok) {
44
		const text = await response.text()
45
		throw new Error(`${response.status} ${text}`)
46
	}
47
	return await response.json()
48
}
49