0

Remove content watcher

by
Published Oct 17, 2025

Removes a user as a watcher from 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
  • Submitted by hugo697 Bun
    Created 284 days ago
    1
    //native
    2
    type Confluence = {
    3
    	email: string
    4
    	apiToken: string
    5
    	domain: string
    6
    }
    7
    /**
    8
     * Remove content watcher
    9
     * Removes a user as a watcher from 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
    	X_Atlassian_Token: string
    26
    ) {
    27
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/user/watch/content/${contentId}`)
    28
    	for (const [k, v] of [
    29
    		['key', key],
    30
    		['username', username],
    31
    		['accountId', accountId]
    32
    	]) {
    33
    		if (v !== undefined && v !== '' && k !== undefined) {
    34
    			url.searchParams.append(k, v)
    35
    		}
    36
    	}
    37
    	const response = await fetch(url, {
    38
    		method: 'DELETE',
    39
    		headers: {
    40
    			'X-Atlassian-Token': X_Atlassian_Token,
    41
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    42
    		},
    43
    		body: undefined
    44
    	})
    45
    	if (!response.ok) {
    46
    		const text = await response.text()
    47
    		throw new Error(`${response.status} ${text}`)
    48
    	}
    49
    	return await response.text()
    50
    }
    51