0

Get macro body by macro ID

by
Published Oct 17, 2025

Returns the body of a macro in storage format, for the given macro ID.

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 macro body by macro ID
9
 * Returns the body of a macro in storage format, for the given macro ID.
10
 */
11
export async function main(auth: Confluence, id: string, version: string, macroId: string) {
12
	const url = new URL(
13
		`https://${auth.domain}/wiki/rest/api/content/${id}/history/${version}/macro/id/${macroId}`
14
	)
15

16
	const response = await fetch(url, {
17
		method: 'GET',
18
		headers: {
19
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
20
		},
21
		body: undefined
22
	})
23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27
	return await response.json()
28
}
29