0

Delete page tree

by
Published Oct 17, 2025

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.

Script confluence
  • Submitted by hugo697 Bun
    Created 284 days ago
    1
    //native
    2
    type Confluence = {
    3
    	email: string
    4
    	apiToken: string
    5
    	domain: string
    6
    }
    7
    /**
    8
     * Delete page tree
    9
     * Moves a pagetree rooted at a page to the space's trash:
    10
    
    
    11
    - If the content's type is `page` and its status is `current`, it will be trashed including
    12
    all its descendants.
    13
     */
    14
    export async function main(auth: Confluence, id: string) {
    15
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/pageTree`)
    16
    
    
    17
    	const response = await fetch(url, {
    18
    		method: 'DELETE',
    19
    		headers: {
    20
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    21
    		},
    22
    		body: undefined
    23
    	})
    24
    	if (!response.ok) {
    25
    		const text = await response.text()
    26
    		throw new Error(`${response.status} ${text}`)
    27
    	}
    28
    	return await response.json()
    29
    }
    30