0

Add new custom content permission to space

by
Published Oct 17, 2025

Adds new custom content permission to space. If the permission to be added is a group permission, the group can be identified by its group name or group id. Note: Only apps can access this REST resource and only make changes to the respective app permissions. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: 'Admin' permission for the space.

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 new custom content permission to space
    9
     * Adds new custom content permission to space.
    10
    
    
    11
    If the permission to be added is a group permission, the group can be identified
    12
    by its group name or group id.
    13
    
    
    14
    Note: Only apps can access this REST resource and only make changes to the respective app permissions.
    15
    
    
    16
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    17
    'Admin' permission for the space.
    18
     */
    19
    export async function main(
    20
    	auth: Confluence,
    21
    	spaceKey: string,
    22
    	body: {
    23
    		subject: { type: 'user' | 'group'; identifier: string }
    24
    		operations: {
    25
    			key: 'read' | 'create' | 'delete'
    26
    			target: string
    27
    			access: false | true
    28
    		}[]
    29
    	}
    30
    ) {
    31
    	const url = new URL(
    32
    		`https://${auth.domain}/wiki/rest/api/space/${spaceKey}/permission/custom-content`
    33
    	)
    34
    
    
    35
    	const response = await fetch(url, {
    36
    		method: 'POST',
    37
    		headers: {
    38
    			'Content-Type': 'application/json',
    39
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    40
    		},
    41
    		body: JSON.stringify(body)
    42
    	})
    43
    	if (!response.ok) {
    44
    		const text = await response.text()
    45
    		throw new Error(`${response.status} ${text}`)
    46
    	}
    47
    	return await response.text()
    48
    }
    49