0

Create audit record

by
Published Oct 17, 2025

Creates a record in the audit log. **[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
     * Create audit record
    9
     * Creates a record in the audit log.
    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
    	body: {
    17
    		author?: {
    18
    			type: 'user'
    19
    			displayName?: string
    20
    			operations?: {}
    21
    			username?: string
    22
    			userKey?: string
    23
    		}
    24
    		remoteAddress: string
    25
    		creationDate?: number
    26
    		summary?: string
    27
    		description?: string
    28
    		category?: string
    29
    		sysAdmin?: false | true
    30
    		affectedObject?: { name: string; objectType: string }
    31
    		changedValues?: {
    32
    			name: string
    33
    			oldValue: string
    34
    			hiddenOldValue?: string
    35
    			newValue: string
    36
    			hiddenNewValue?: string
    37
    		}[]
    38
    		associatedObjects?: { name: string; objectType: string }[]
    39
    	}
    40
    ) {
    41
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/audit`)
    42
    
    
    43
    	const response = await fetch(url, {
    44
    		method: 'POST',
    45
    		headers: {
    46
    			'Content-Type': 'application/json',
    47
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    48
    		},
    49
    		body: JSON.stringify(body)
    50
    	})
    51
    	if (!response.ok) {
    52
    		const text = await response.text()
    53
    		throw new Error(`${response.status} ${text}`)
    54
    	}
    55
    	return await response.json()
    56
    }
    57