0

Get content templates

by
Published Oct 17, 2025

Returns all content templates. Use this method to retrieve all global content templates or all content templates in a space. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: 'View' permission for the space to view space templates and permission to access the Confluence site ('Can use' global permission) to view global templates.

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 templates
    9
     * Returns all content templates. Use this method to retrieve all global
    10
    content templates or all content templates in a space.
    11
    
    
    12
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    13
    'View' permission for the space to view space templates and permission to
    14
    access the Confluence site ('Can use' global permission) to view global templates.
    15
     */
    16
    export async function main(
    17
    	auth: Confluence,
    18
    	spaceKey: string | undefined,
    19
    	start: string | undefined,
    20
    	limit: string | undefined,
    21
    	expand: string | undefined
    22
    ) {
    23
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/template/page`)
    24
    	for (const [k, v] of [
    25
    		['spaceKey', spaceKey],
    26
    		['start', start],
    27
    		['limit', limit],
    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: 'GET',
    36
    		headers: {
    37
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    38
    		},
    39
    		body: undefined
    40
    	})
    41
    	if (!response.ok) {
    42
    		const text = await response.text()
    43
    		throw new Error(`${response.status} ${text}`)
    44
    	}
    45
    	return await response.json()
    46
    }
    47