0

Get content state

by
Published Oct 17, 2025

Gets the current content state of the draft or current version of content. To specify the draft version, set the parameter status to draft, otherwise archived or current will get the relevant published state. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to view 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
     * Get content state
    9
     * Gets the current content state of the draft or current version of content. To specify the draft version, set
    10
    the parameter status to draft, otherwise archived or current will get the relevant published state.
    11
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    12
    Permission to view the content.
    13
     */
    14
    export async function main(
    15
    	auth: Confluence,
    16
    	id: string,
    17
    	status: 'current' | 'draft' | 'archived' | undefined
    18
    ) {
    19
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/state`)
    20
    	for (const [k, v] of [['status', status]]) {
    21
    		if (v !== undefined && v !== '' && k !== undefined) {
    22
    			url.searchParams.append(k, v)
    23
    		}
    24
    	}
    25
    	const response = await fetch(url, {
    26
    		method: 'GET',
    27
    		headers: {
    28
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    29
    		},
    30
    		body: undefined
    31
    	})
    32
    	if (!response.ok) {
    33
    		const text = await response.text()
    34
    		throw new Error(`${response.status} ${text}`)
    35
    	}
    36
    	return await response.json()
    37
    }
    38