Edits history of script submission #15246 for ' Delete content version (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Delete content version
     * Delete a historical version. This does not delete the changes made to the
    content in that version, rather the changes for the deleted version are
    rolled up into the next version. Note, you cannot delete the current version.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    Permission to update the content.
     */
    export async function main(auth: Confluence, id: string, versionNumber: string) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/version/${versionNumber}`)
    
    	const response = await fetch(url, {
    		method: 'DELETE',
    		headers: {
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 235 days ago