Edits history of script submission #15338 for ' Set retention period (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Set retention period
     * 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.
     */
    export async function main(
    	auth: Confluence,
    	body: {
    		number: number
    		units:
    			| 'NANOS'
    			| 'MICROS'
    			| 'MILLIS'
    			| 'SECONDS'
    			| 'MINUTES'
    			| 'HOURS'
    			| 'HALF_DAYS'
    			| 'DAYS'
    			| 'WEEKS'
    			| 'MONTHS'
    			| 'YEARS'
    			| 'DECADES'
    			| 'CENTURIES'
    			| 'MILLENNIA'
    			| 'ERAS'
    			| 'FOREVER'
    	}
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/audit/retention`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago