Edits history of script submission #15247 for ' Delete page tree (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Delete page tree
     * Moves a pagetree rooted at a page to the space's trash:
    
    - If the content's type is `page` and its status is `current`, it will be trashed including
    all its descendants.
     */
    export async function main(auth: Confluence, id: string) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/pageTree`)
    
    	const response = await fetch(url, {
    		method: 'DELETE',
    		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