0

Publish shared draft

by
Published Oct 17, 2025

Publishes a shared draft of a page created from a blueprint. By default, the following objects are expanded: `body.storage`, `history`, `space`, `version`, `ancestors`. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to view the draft and 'Add' permission for the space that the content will be created in.

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 shared draft
    9
     * Publishes a shared draft of a page created from a blueprint.
    10
    
    
    11
    By default, the following objects are expanded: `body.storage`, `history`, `space`, `version`, `ancestors`.
    12
    
    
    13
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    14
    Permission to view the draft and 'Add' permission for the space that
    15
    the content will be created in.
    16
     */
    17
    export async function main(
    18
    	auth: Confluence,
    19
    	draftId: string,
    20
    	status: string | undefined,
    21
    	expand: string | undefined,
    22
    	body: {
    23
    		version: { number: number }
    24
    		title: string
    25
    		type: 'page'
    26
    		status?: 'current'
    27
    		space?: { key: string }
    28
    		ancestors?: { id: string }[]
    29
    	}
    30
    ) {
    31
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/blueprint/instance/${draftId}`)
    32
    	for (const [k, v] of [
    33
    		['status', status],
    34
    		['expand', expand]
    35
    	]) {
    36
    		if (v !== undefined && v !== '' && k !== undefined) {
    37
    			url.searchParams.append(k, v)
    38
    		}
    39
    	}
    40
    	const response = await fetch(url, {
    41
    		method: 'PUT',
    42
    		headers: {
    43
    			'Content-Type': 'application/json',
    44
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    45
    		},
    46
    		body: JSON.stringify(body)
    47
    	})
    48
    	if (!response.ok) {
    49
    		const text = await response.text()
    50
    		throw new Error(`${response.status} ${text}`)
    51
    	}
    52
    	return await response.json()
    53
    }
    54