0

Move a page to a new location relative to a target page

by
Published Oct 17, 2025

Move a page to a new location relative to a target page: * `before` - move the page under the same parent as the target, before the target in the list of children * `after` - move the page under the same parent as the target, after the target in the list of children * `append` - move the page to be a child of the target Caution: This API can move pages to the top level of a space.

Script confluence Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Confluence = {
3
	email: string
4
	apiToken: string
5
	domain: string
6
}
7
/**
8
 * Move a page to a new location relative to a target page
9
 * Move a page to a new location relative to a target page:
10

11
* `before` - move the page under the same parent as the target, before the target in the list of children
12
* `after` - move the page under the same parent as the target, after the target in the list of children
13
* `append` - move the page to be a child of the target
14

15
Caution: This API can move pages to the top level of a space.
16
 */
17
export async function main(
18
	auth: Confluence,
19
	pageId: string,
20
	position: 'before' | 'after' | 'append',
21
	targetId: string
22
) {
23
	const url = new URL(
24
		`https://${auth.domain}/wiki/rest/api/content/${pageId}/move/${position}/${targetId}`
25
	)
26

27
	const response = await fetch(url, {
28
		method: 'PUT',
29
		headers: {
30
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
31
		},
32
		body: undefined
33
	})
34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38
	return await response.json()
39
}
40