0

Removes the content state of a content and publishes a new version.

by
Published Oct 17, 2025

Removes the content state of the content specified and creates a new version (publishes the content without changing the body) of the content with the new status. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to edit the content.

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
     * Removes the content state of a content and publishes a new version.
    9
     * Removes the content state of the content specified and creates a new version
    10
    (publishes the content without changing the body) of the content with the new status.
    11
    
    
    12
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    13
    Permission to edit the content.
    14
     */
    15
    export async function main(auth: Confluence, id: string, status: 'current' | 'draft' | undefined) {
    16
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/state`)
    17
    	for (const [k, v] of [['status', status]]) {
    18
    		if (v !== undefined && v !== '' && k !== undefined) {
    19
    			url.searchParams.append(k, v)
    20
    		}
    21
    	}
    22
    	const response = await fetch(url, {
    23
    		method: 'DELETE',
    24
    		headers: {
    25
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    26
    		},
    27
    		body: undefined
    28
    	})
    29
    	if (!response.ok) {
    30
    		const text = await response.text()
    31
    		throw new Error(`${response.status} ${text}`)
    32
    	}
    33
    	return await response.json()
    34
    }
    35