Edits history of script submission #15233 for ' Check content permissions (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Check content permissions
     * Check if a user or a group can perform an operation to the specified content.
     */
    export async function main(
    	auth: Confluence,
    	id: string,
    	body: {
    		subject: { type: 'user' | 'group'; identifier: string }
    		operation: 'read' | 'update' | 'delete'
    	}
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/permission/check`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago