Can the importSpace API method be used with a local export file?
Asked by Brad:

I used the Confluence CLI to export a space from one of our production servers and I want to import that zip file into another server using the SOAP API importSpace method.

Do I need to copy this file out to the "restore" folder on the destination server before running importSpace?

Right now I have the zip file sitting in my local temp directory on my laptop and the import is failing with the following errors.

XML Response:

HTTP Response from https://someserver:8443/confluence/plugins/servlet/soap-axis1/confluenceservice-v2 (status: 500):  
\<?xml version="1.0" encoding="utf-8"?\>\<soapenv:Envelope xmlns:soapenv="<http://schemas.xmlsoap.org/soap/envelope/>" xmlns:xsd="<http://www.w3.org/2001/XMLSchema>" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\>\<soapenv:Body\>\<soapenv:Fault\>\<faultcode\>soapenv:Server.userException\</faultcode\>\<faultstring\>com.atlassian.confluence.rpc.RemoteException: Could not import space\</faultstring\>\<detail\>\<com.atlassian.confluence.rpc.RemoteException xsi:type="ns1:RemoteException" xmlns:ns1="http://rpc.confluence.atlassian.com"/\>\<ns2:hostname xmlns:ns2="http://xml.apache.org/axis/"\>ServerName\</ns2:hostname\>\</detail\>\</soapenv:Fault\>\</soapenv:Body\>\</soapenv:Envelope\>

Log File Entry (destination server):

2019-05-03 08:15:23,410 INFO \[https-jsse-nio-8443-exec-25\] \[confluence.rpc.auth.TokenAuthenticationInvocationHandler\] invokeAuthenticatedMethod Executing remote API method \[ importSpace \] as user \[ admin \]  
2019-05-03 08:15:23,422 ERROR \[https-jsse-nio-8443-exec-25\] \[confluence.util.zip.FileUnzipper\] unzipFileInArchive Entry \[exportDescriptor.properties\] could not be found in \[C:\\Program Files\\Atlassian\\Confluence\\temp\\confluence-import-5848877068392222338.tmp\]  
-- url: /confluence/plugins/servlet/soap-axis1/confluenceservice-v2 \| traceId: 0ca67b497ed6a611 \| userName: admin \| method: importSpace  
2019-05-03 08:15:23,423 WARN \[https-jsse-nio-8443-exec-25\] \[confluence.rpc.auth.TokenAuthenticationInvocationHandler\] invokeAuthenticatedMethod Failure executing remote method \[importSpace\]: The zip file did not contain an entry 'exportDescriptor.properties'. It did not contain any files, or was not a valid zip file.

As a shot in the dark I re-zipped the archive with 7-zip and the import still freaks out.

Any ideas? Thanks


Answers:
author: Tobias Meyer
body: Hi [@Brad](/t5/user/viewprofilepage/user-id/748892)

Quite old your request but I struggled today with the exact same error message and managed to get it to work.

This python method does the trick for me. Maybe it's also helpful for you...

```
def importSpaceSOAP(self, file):
    logging.info(f'Try to import space: {file}')
    client = SOAPClient(self.url + '/rpc/soap-axis/confluenceservice-v2?wsdl', timeout=1200)
    try:
        with open(file, "rb") as f:
            encoded_file = base64.b64encode(f.read())
            response = client.service.importSpace(self.token, encoded_file.decode())
            return response
    except xmlrpc.client.Fault as e:
        logging.error(e)
        return False
    except socket.timeout as e:
        logging.error(e)
        return False
```


author: Stephen Sifers
body: Hello Brad,

Thank you for providing excellent detail and the steps you're taking to produce the error reported. Much appreciation for sending over the log error you're also receiving.

From reviewing your logs I see two items that need to be addressed.

Firstly, the error "ERROR \[https-jsse-nio-8443-exec-25\] \[confluence.util.zip.FileUnzipper\] unzipFileInArchive Entry \[exportDescriptor.properties\] could not be found in" is reporting that the file it's looking for within the server is not present. Please ensure when you're executing your restore/import that the zip file is located within the proper locations (home folder or temp).

Secondly, "WARN \[https-jsse-nio-8443-exec-25\] \[confluence.rpc.auth.TokenAuthenticationInvocationHandler\] invokeAuthenticatedMethod Failure executing remote method \[importSpace\]: The zip file did not contain an entry 'exportDescriptor.properties'." is reporting your backup file is invalid. There is an article which covers how to ensure your backup files stay valid while working with them. You may find this article at [XML backup restore failed with 'The zip file did not contain an entry 'exportDescriptor.properties'' in Confluence](https://confluence.atlassian.com/confkb/xml-backup-restore-failed-with-the-zip-file-did-not-contain-an-entry-exportdescriptor-properties-in-confluence-300811533.html)

Something else you should be aware of is that the SOAP API has been deprecated since Confluence 5.5 and has since been replaced with the REST API. Here is the notice of deprecation:
> The XML-RPC and SOAP APIs are **deprecated since** **Confluence 5.5**, and may not work as expected.
>
> Confluence has a new [REST API](https://developer.atlassian.com/server/confluence/confluence-server-rest-api) that is progressively replacing our existing APIs. We recommend plugin developers use the new REST APIs where possible.
>
> Note that for Confluence Cloud, [API tokens](https://confluence.atlassian.com/display/Cloud/API+tokens) do not support the XML-RPC and SOAP APIs.

Source document: [Confluence XML-RPC and SOAP APIs](https://developer.atlassian.com/server/confluence/confluence-xml-rpc-and-soap-apis/)

I hope this proves helpful and you're able to restore your Confluence instance.

Regards,  
Stephen Sifers

comments: author: Brad
body: Unfortunately your REST API doesn't have an option to import a space (at least I didn't see one). I would love to abandon SOAP.

I think your comment sums up my problem when you mentioned that my zip file needs to be in the "home folder or temp" directory. I'm assuming this is on the server? One of the problems with this is that security isn't going to share those folders out. So I have no way of uploading a zip file to restore from. I was hoping that I could restore a site based on a file that is located on my local client, but that doesn't seem possible at this time.

Appreciate the help.


Tags: atl-adm

confluence-server

server