0

Copy page hierarchy

by
Published Oct 17, 2025

Copy page hierarchy allows the copying of an entire hierarchy of pages and their associated properties, permissions and attachments.

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
     * Copy page hierarchy
    9
     * Copy page hierarchy allows the copying of an entire hierarchy of pages and their associated properties, permissions and attachments.
    10
     */
    11
    export async function main(
    12
    	auth: Confluence,
    13
    	id: string,
    14
    	body: {
    15
    		copyAttachments?: false | true
    16
    		copyPermissions?: false | true
    17
    		copyProperties?: false | true
    18
    		copyLabels?: false | true
    19
    		copyCustomContents?: false | true
    20
    		copyDescendants?: false | true
    21
    		destinationPageId: string
    22
    		titleOptions?: { prefix?: string; replace?: string; search?: string }
    23
    	}
    24
    ) {
    25
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/pagehierarchy/copy`)
    26
    
    
    27
    	const response = await fetch(url, {
    28
    		method: 'POST',
    29
    		headers: {
    30
    			'Content-Type': 'application/json',
    31
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    32
    		},
    33
    		body: JSON.stringify(body)
    34
    	})
    35
    	if (!response.ok) {
    36
    		const text = await response.text()
    37
    		throw new Error(`${response.status} ${text}`)
    38
    	}
    39
    	return await response.json()
    40
    }
    41