Edits history of script submission #15235 for ' Copy single page (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Copy single page
     * Copies a single page and its associated properties, permissions, attachments, and custom contents.
     */
    export async function main(
    	auth: Confluence,
    	id: string,
    	expand: string | undefined,
    	body: {
    		copyAttachments?: false | true
    		copyPermissions?: false | true
    		copyProperties?: false | true
    		copyLabels?: false | true
    		copyCustomContents?: false | true
    		destination: {
    			type: 'space' | 'existing_page' | 'parent_page' | 'parent_content'
    			value: string
    		}
    		pageTitle?: string
    		body?: {
    			storage?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			editor2?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    		}
    	}
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/copy`)
    	for (const [k, v] of [['expand', expand]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	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.text()
    }
    

    Submitted by hugo697 235 days ago