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.

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.

Solution

Choose the option that matches how you want to run the bulk archive operation:

Option

Method

CSV Requirements

Best for

Option 1

Python script (bulkArchive.py)

One space key per line, no header

Automated CLI execution or programmatic workflows

Option 2

Postman collection

Must include the spacekeyheader

Visual API testing or GUI-based execution

Both options use the Confluence update space API (PUT /wiki/rest/api/space/{spaceKey}) and set the space status to archived.

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()

Before you run the script:

  • Install the requests library by running pip install requests.

  • Set CONFLUENCE_EMAIL and CONFLUENCE_API_TOKEN as environment variables.

  • Replace <YOUR_DOMAIN> and CSV_FILE_PATH in the script as needed.

  • Prepare a CSV file with one space key per line and no header.

Example:

CDE DEF Run bulkArchive.py after you complete the preparation steps.

Resolution steps

  1. Install the requests library (if not already) by running the command: pip install requests.

  2. 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"

  3. Replace <YOUR_DOMAIN> and CSV_FILE_PATH as needed.

  4. Prepare your CSV file with one space key per line, no header. Example below:

    • CDE

    • DEF

  5. Run the script bulkArchive.py.

  6. After the script runs, review its output for each space:

    1. A 200 response prints that the space was archived successfully.

    2. Another response status prints that the archive failed, along with the status and response text.

    Double-check the archived spaces after the script finishes.

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:

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

Prepare a CSV file that includes the spacekey header and all target space keys. Then download Postman, save both JSON files, import them into Postman, generate the API token, and run the Bulk Archive Spaces collection.

Check the response for the archived spaces after the collection runs.

Updated on October 1, 2026

Still need help?

The Atlassian Community is here for you.