0

Get label information

by
Published Oct 17, 2025

Returns label information and a list of contents associated with the label. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to access the Confluence site ('Can use' global permission). Only contents that the user is permitted to view is returned.

Script confluence Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Confluence = {
3
	email: string
4
	apiToken: string
5
	domain: string
6
}
7
/**
8
 * Get label information
9
 * Returns label information and a list of contents associated with the label.
10

11
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
12
Permission to access the Confluence site ('Can use' global permission). Only contents
13
that the user is permitted to view is returned.
14
 */
15
export async function main(
16
	auth: Confluence,
17
	name: string | undefined,
18
	_type: 'page' | 'blogpost' | 'attachment' | 'page_template' | undefined,
19
	start: string | undefined,
20
	limit: string | undefined
21
) {
22
	const url = new URL(`https://${auth.domain}/wiki/rest/api/label`)
23
	for (const [k, v] of [
24
		['name', name],
25
		['type', _type],
26
		['start', start],
27
		['limit', limit]
28
	]) {
29
		if (v !== undefined && v !== '' && k !== undefined) {
30
			url.searchParams.append(k, v)
31
		}
32
	}
33
	const response = await fetch(url, {
34
		method: 'GET',
35
		headers: {
36
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
37
		},
38
		body: undefined
39
	})
40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44
	return await response.json()
45
}
46