0

Export audit records

by
Published Oct 17, 2025

Exports audit records as a CSV file or ZIP file. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: 'Confluence Administrator' global permission.

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
 * Export audit records
9
 * Exports audit records as a CSV file or ZIP file.
10

11
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
12
'Confluence Administrator' global permission.
13
 */
14
export async function main(
15
	auth: Confluence,
16
	startDate: string | undefined,
17
	endDate: string | undefined,
18
	searchString: string | undefined,
19
	format: 'csv' | 'zip' | undefined
20
) {
21
	const url = new URL(`https://${auth.domain}/wiki/rest/api/audit/export`)
22
	for (const [k, v] of [
23
		['startDate', startDate],
24
		['endDate', endDate],
25
		['searchString', searchString],
26
		['format', format]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'GET',
34
		headers: {
35
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
36
		},
37
		body: undefined
38
	})
39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`${response.status} ${text}`)
42
	}
43
	return await response.text()
44
}
45