Bulk archive spaces using the Confluence Cloud API and CSV file input
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
This KB covers how to bulk archive spaces as the bulk space operation function via the UI isn't available for archiving spaces.
Solution
The example script provided is intended for demonstration purposes only and is not officially supported by Atlassian. If you choose to use or modify this script, please do so at your own risk, as Atlassian Support can’t assist with troubleshooting, maintenance, or customization of example scripts. For official support, please refer to Atlassian’s supported products and services.
Option 1: Python script
Copy the following code to a local file. In this example we will name it bulkArchive.py
.
import csv
import os
import requests
from requests.auth import HTTPBasicAuth
# --- Configuration ---
CONFLUENCE_BASE_URL = "https://<YOUR_DOMAIN>.atlassian.net/wiki" # Replace <YOUR_DOMAIN> with the target doamin
EMAIL = os.getenv("CONFLUENCE_EMAIL") # Set as environment variable
API_TOKEN = os.getenv("CONFLUENCE_API_TOKEN") # Set as environment variable
CSV_FILE_PATH = "space_keys.csv" # Path to your CSV file
def archive_space(space_key):
url = f"{CONFLUENCE_BASE_URL}/rest/api/space/{space_key}"
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
data = {
"status": "archived"
}
response = requests.put(
url,
auth=HTTPBasicAuth(EMAIL, API_TOKEN),
headers=headers,
json=data
)
if response.status_code == 200:
print(f"Space '{space_key}' archived successfully.")
else:
print(f"Failed to archive '{space_key}'. Status: {response.status_code}, Response: {response.text}")
def main():
with open(CSV_FILE_PATH, newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
space_key = row[0].strip()
if space_key:
archive_space(space_key)
if __name__ == "__main__":
main()
Resolution steps
Install the requests library (if not already) by running the command:
pip install requests.
Set your credentials as environment variables before running the script (recommend for security):
export CONFLUENCE_EMAIL="your_email@example.com"
export CONFLUENCE_API_TOKEN="your_api_token"
Replace <YOUR_DOMAIN> and CSV_FILE_PATH as needed.
Prepare your CSV file with one space key per line, no header. Example below:
CDE
DEF
Run the script
bulkArchive.py
.Double check the archived spaces.
Please note that we have outlined the following feature requests to address these issues:
Option 2: Postman
Prerequisite
This resolution option uses the Confluence update space API via postman:
https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}
with "status": "archived" as the JSON request body
Save the following as JSON files for Postman import.
Bulk archive spaces
{
"info": {
"_postman_id": "56b3fecd-c662-4a94-b049-c007d708c52d",
"name": "Bulk Archive Spaces",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "25367731"
},
"item": [
{
"name": "ArchiveSpaces",
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"content-type": true,
"accept": true
}
},
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "{{site-name}}",
"type": "string"
},
{
"key": "username",
"value": "{{username}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\"status\": \"archived\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{username}}/wiki/rest/api/space/{{spacekey}}",
"protocol": "https",
"host": [
"{{username}}"
],
"path": [
"wiki",
"rest",
"api",
"space",
"{{spacekey}}"
]
}
},
"response": []
}
]
}
Bulk space operations
{
"id": "a8f7e52d-875e-4d40-8e94-aa5ab7673efe",
"name": "BulkSpaceOperation",
"values": [
{
"key": "site-name",
"value": "Your site's base URL",
"type": "default",
"enabled": true
},
{
"key": "username",
"value": "Your email address",
"type": "default",
"enabled": true
},
{
"key": "api-token",
"value": "Your API token",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2025-09-04T06:13:35.644Z",
"_postman_exported_using": "Postman/11.61.7"
}
Resolution steps
Download Postman (if not already done)
Copy and save both JSONs above
Import the JSON files to Postman
Generate the API token for running the Confluence API
Run the Bulk Archive Spaces.postman_collection in Postman and select the CSV file that includes all target space keys with the headerspacekey
Check the response for the archived spaces as required
Was this helpful?