Confluence Space import via scripting tools
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
This guide is for informational purposes and is not eligible for support from Atlassian. If you have any questions about the information on this page, please reach out to our Atlassian Community for help.
Summary
Currently there are no REST API methods in Confluence for Space export or import.
We do currently have an open feature request to Add REST API endpoint for generating space exports being managed under CONFSERVER-40457 - Getting issue details... STATUS . please make sure to vote, comment and watch that feature request if you are interested on it.
If an admin wishes to make these operations less manual and automate them to a certain extent, they can rely on Confluence's XML-RPC and SOAP APIs. However, these APIs are deprecated since Confluence 5.5.
Scripting
Another way to accomplish this is to script these tasks. To do so we'll need to rely on some cookies and tokens to emulate the UI activity via command line.
Essentially, we'll need to capture the atlassian-token and the JSESSIONID cookies when authenticating with Confluence. These headers can be found in a browser's Developer Tools.
You can retrieve these with a script (shell or python examples below) to automate the Space import operation.
For reference: CONFSERVER-40457 - Getting issue details... STATUS
Environment
The space import scripts below were tested on:
Confluence DC 7.4.3 (server)
Linux (Centos 7) and Mac (Catalina) (clients)
Requirements
The Python version will run only on Python 3 and it requires four modules: requests, bs4, html5lib and lxml.
The shell version will require GNU Bash 3.2 and upwards.
The space backup file must already reside in the <confluence-shared-home/restore> directory. The scripts will not upload the file to that location.
Solution
Space import with Bash/Python
The Bash version uses curl to make the HTTP requests and store the token and cookies required. Then it'll send the payload to Confluence's endpoints.
The Python version will rely on libraries (the requests module will take care of that auth/token part).
Variables
Both scripts require the admin to adjust a few necessary information for them to run:
- admin username
- admin password
- Confluence base URL
- space export backup file name
- index to be performed post-space-import (true or false)
Output
You should expect something like this as a successful result:
Error handling
Both scripts will handle errors for:
- authentication
- token retrieval
- space import