Edits history of script submission #15314 for ' Move a page to a new location relative to a target page (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Move a page to a new location relative to a target page
     * 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.
     */
    export async function main(
    	auth: Confluence,
    	pageId: string,
    	position: 'before' | 'after' | 'append',
    	targetId: string
    ) {
    	const url = new URL(
    		`https://${auth.domain}/wiki/rest/api/content/${pageId}/move/${position}/${targetId}`
    	)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		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