0

Get audit records

by
Published Oct 17, 2025

Returns all records in the audit log, optionally for a certain date range. This contains information about events like space exports, group membership changes, app installations, etc. For more information, see [Audit log](https://confluence.atlassian.com/confcloud/audit-log-802164269.html) in the Confluence administrator's guide. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: 'Confluence Administrator' global permission.

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 audit records
    9
     * Returns all records in the audit log, optionally for a certain date range.
    10
    This contains information about events like space exports, group membership
    11
    changes, app installations, etc. For more information, see
    12
    [Audit log](https://confluence.atlassian.com/confcloud/audit-log-802164269.html)
    13
    in the Confluence administrator's guide.
    14
    
    
    15
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    16
    'Confluence Administrator' global permission.
    17
     */
    18
    export async function main(
    19
    	auth: Confluence,
    20
    	startDate: string | undefined,
    21
    	endDate: string | undefined,
    22
    	searchString: string | undefined,
    23
    	start: string | undefined,
    24
    	limit: string | undefined
    25
    ) {
    26
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/audit`)
    27
    	for (const [k, v] of [
    28
    		['startDate', startDate],
    29
    		['endDate', endDate],
    30
    		['searchString', searchString],
    31
    		['start', start],
    32
    		['limit', limit]
    33
    	]) {
    34
    		if (v !== undefined && v !== '' && k !== undefined) {
    35
    			url.searchParams.append(k, v)
    36
    		}
    37
    	}
    38
    	const response = await fetch(url, {
    39
    		method: 'GET',
    40
    		headers: {
    41
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    42
    		},
    43
    		body: undefined
    44
    	})
    45
    	if (!response.ok) {
    46
    		const text = await response.text()
    47
    		throw new Error(`${response.status} ${text}`)
    48
    	}
    49
    	return await response.json()
    50
    }
    51