0

Set retention period

by
Published Oct 17, 2025

Sets the retention period for records in the audit log. The retention period can be set to a maximum of 1 year. **[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
 * Set retention period
9
 * Sets the retention period for records in the audit log. The retention period
10
can be set to a maximum of 1 year.
11

12
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
13
'Confluence Administrator' global permission.
14
 */
15
export async function main(
16
	auth: Confluence,
17
	body: {
18
		number: number
19
		units:
20
			| 'NANOS'
21
			| 'MICROS'
22
			| 'MILLIS'
23
			| 'SECONDS'
24
			| 'MINUTES'
25
			| 'HOURS'
26
			| 'HALF_DAYS'
27
			| 'DAYS'
28
			| 'WEEKS'
29
			| 'MONTHS'
30
			| 'YEARS'
31
			| 'DECADES'
32
			| 'CENTURIES'
33
			| 'MILLENNIA'
34
			| 'ERAS'
35
			| 'FOREVER'
36
	}
37
) {
38
	const url = new URL(`https://${auth.domain}/wiki/rest/api/audit/retention`)
39

40
	const response = await fetch(url, {
41
		method: 'PUT',
42
		headers: {
43
			'Content-Type': 'application/json',
44
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
45
		},
46
		body: JSON.stringify(body)
47
	})
48
	if (!response.ok) {
49
		const text = await response.text()
50
		throw new Error(`${response.status} ${text}`)
51
	}
52
	return await response.json()
53
}
54