0

Delete space

by
Published Oct 17, 2025

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.

Script confluence Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Confluence = {
3
	email: string
4
	apiToken: string
5
	domain: string
6
}
7
/**
8
 * Delete space
9
 * Permanently deletes a space without sending it to the trash. Note, the space will be deleted in a long running task.
10
Therefore, the space may not be deleted yet when this method has
11
returned. Clients should poll the status link that is returned in the
12
response until the task completes.
13

14
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
15
'Admin' permission for the space.
16
 */
17
export async function main(auth: Confluence, spaceKey: string) {
18
	const url = new URL(`https://${auth.domain}/wiki/rest/api/space/${spaceKey}`)
19

20
	const response = await fetch(url, {
21
		method: 'DELETE',
22
		headers: {
23
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
24
		},
25
		body: undefined
26
	})
27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31
	return await response.json()
32
}
33