//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Copy page hierarchy
* Copy page hierarchy allows the copying of an entire hierarchy of pages and their associated properties, permissions and attachments.
*/
export async function main(
auth: Confluence,
id: string,
body: {
copyAttachments?: false | true
copyPermissions?: false | true
copyProperties?: false | true
copyLabels?: false | true
copyCustomContents?: false | true
copyDescendants?: false | true
destinationPageId: string
titleOptions?: { prefix?: string; replace?: string; search?: string }
}
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/pagehierarchy/copy`)
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