0

Get content in space with given content state

by
Published Oct 17, 2025

Returns all content that has the provided content state in a space. If the expand query parameter is used with the `body.export_view` and/or `body.styled_view` properties, then the query limit parameter will be restricted to a maximum value of 25. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: 'View' permission for the space.

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 in space with given content state
    9
     * Returns all content that has the provided content state in a space.
    10
    
    
    11
    If the expand query parameter is used with the `body.export_view` and/or `body.styled_view` properties, then the query limit parameter will be restricted to a maximum value of 25.
    12
    
    
    13
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    14
    'View' permission for the space.
    15
     */
    16
    export async function main(
    17
    	auth: Confluence,
    18
    	spaceKey: string,
    19
    	state_id: string | undefined,
    20
    	expand: string | undefined,
    21
    	limit: string | undefined,
    22
    	start: string | undefined
    23
    ) {
    24
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/space/${spaceKey}/state/content`)
    25
    	for (const [k, v] of [
    26
    		['state-id', state_id],
    27
    		['expand', expand],
    28
    		['limit', limit],
    29
    		['start', start]
    30
    	]) {
    31
    		if (v !== undefined && v !== '' && k !== undefined) {
    32
    			url.searchParams.append(k, v)
    33
    		}
    34
    	}
    35
    	const response = await fetch(url, {
    36
    		method: 'GET',
    37
    		headers: {
    38
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    39
    		},
    40
    		body: undefined
    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