Edits history of script submission #15250 for ' Delete space (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Delete space
     * Permanently deletes a space without sending it to the trash. Note, the space will be deleted in a long running task.
    Therefore, the space may not be deleted yet when this method has
    returned. Clients should poll the status link that is returned in the
    response until the task completes.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    'Admin' permission for the space.
     */
    export async function main(auth: Confluence, spaceKey: string) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/space/${spaceKey}`)
    
    	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.json()
    }
    

    Submitted by hugo697 235 days ago