Edits history of script submission #15293 for ' Get restrictions by operation (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Get restrictions by operation
     * Returns restrictions on a piece of content by operation. This method is
    similar to [Get restrictions](#api-content-id-restriction-get) except that
    the operations are properties of the return object, rather than items in
    a results array.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    Permission to view the content.
     */
    export async function main(auth: Confluence, id: string, expand: string | undefined) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/restriction/byOperation`)
    	for (const [k, v] of [['expand', expand]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago