0

Add group to content restriction

by
Published Oct 17, 2025

Adds a group to a content restriction by Group Id. That is, grant read or update permission to the group for a piece of content. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to edit the content.

Script confluence
  • Submitted by hugo697 Bun
    Created 268 days ago
    1
    //native
    2
    type Confluence = {
    3
    	email: string
    4
    	apiToken: string
    5
    	domain: string
    6
    }
    7
    /**
    8
     * Add group to content restriction
    9
     * Adds a group to a content restriction by Group Id. That is, grant read or update
    10
    permission to the group for a piece of content.
    11
    
    
    12
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    13
    Permission to edit the content.
    14
     */
    15
    export async function main(
    16
    	auth: Confluence,
    17
    	id: string,
    18
    	operationKey: 'read' | 'update',
    19
    	groupId: string
    20
    ) {
    21
    	const url = new URL(
    22
    		`https://${auth.domain}/wiki/rest/api/content/${id}/restriction/byOperation/${operationKey}/byGroupId/${groupId}`
    23
    	)
    24
    
    
    25
    	const response = await fetch(url, {
    26
    		method: 'PUT',
    27
    		headers: {
    28
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    29
    		},
    30
    		body: undefined
    31
    	})
    32
    	if (!response.ok) {
    33
    		const text = await response.text()
    34
    		throw new Error(`${response.status} ${text}`)
    35
    	}
    36
    	return await response.text()
    37
    }
    38