0

Publish legacy draft

by
Published Oct 17, 2025

Publishes a legacy draft of a page created from a blueprint.

Script confluence
  • Submitted by hugo697 Bun
    Created 284 days ago
    1
    //native
    2
    type Confluence = {
    3
    	email: string
    4
    	apiToken: string
    5
    	domain: string
    6
    }
    7
    /**
    8
     * Publish legacy draft
    9
     * Publishes a legacy draft of a page created from a blueprint.
    10
     */
    11
    export async function main(
    12
    	auth: Confluence,
    13
    	draftId: string,
    14
    	status: string | undefined,
    15
    	expand: string | undefined,
    16
    	body: {
    17
    		version: { number: number }
    18
    		title: string
    19
    		type: 'page'
    20
    		status?: 'current'
    21
    		space?: { key: string }
    22
    		ancestors?: { id: string }[]
    23
    	}
    24
    ) {
    25
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/blueprint/instance/${draftId}`)
    26
    	for (const [k, v] of [
    27
    		['status', status],
    28
    		['expand', expand]
    29
    	]) {
    30
    		if (v !== undefined && v !== '' && k !== undefined) {
    31
    			url.searchParams.append(k, v)
    32
    		}
    33
    	}
    34
    	const response = await fetch(url, {
    35
    		method: 'POST',
    36
    		headers: {
    37
    			'Content-Type': 'application/json',
    38
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    39
    		},
    40
    		body: JSON.stringify(body)
    41
    	})
    42
    	if (!response.ok) {
    43
    		const text = await response.text()
    44
    		throw new Error(`${response.status} ${text}`)
    45
    	}
    46
    	return await response.json()
    47
    }
    48