Export and Import Translation ZIP via REST API
You can use the REST API to automatically export and import the Translation ZIP.
Create the translation ZIP file
If Scroll Versions is activated in the space you are exporting, you first have to get the version ID of the version you want to export.
You can do this by sending a GET request to:<confluence-base-url>/rest/scroll-versions/1.0/versions/<spaceKey>
The response will look like this:
[
{
"id": "<versionId>",
"name": "<versionName>",
...
},
...
]
Then send a POST request with Content-Type: application/json to:<confluence-base-url>/rest/scroll-versions/1.0/translation/start
The body should consist of data with following parameters:
Key | Value |
---|---|
languageKey | The key of the language to export (e.g. 'en' for english). |
outdatedOnly | 'true' if only pages with status 'outdated' should be exported, else 'false'. |
provider |
|
spaceKey | The spacekey of the space you want to export. |
| The ID of the variant you want to export, 'all' for every variant. |
versionId (optional - only if Version Management is activated) | The ID of the version you want to export. |
oneFilePerPage (optional) | false (default) or true. When using 'xliff' for provider , this parameter has to be defined in the body and set to true value |
includeLabels (optional) | A list of label names (as strings). Only pages with any of the provided labels are exported. E.g. ["label1", "label2"] |
excludeLabels (optional) | A list of label names (as strings). All pages with any of the provided labels are excluded from the export. E.g. ["label1", "label2"] |
excludeFallbacks (optional) | 'true' if versioned pages without changes in the exported version should not be exported. |
excludeUnversioned (optional) | 'true' if unversioned pages should not be exported. |
onlyUnversioned (optional) | 'true' if only unversioned pages should be exported. |
The respond looks like this:
{
"id": "<taskId>",
...
}
To check the created file send the following get request:<confluence-base-url>/rest/scroll-versions/1.0/async-tasks/<taskId>?since=<dateTime>
If the file was successfully created, the response will look like this:
{
"id": "<taskId>",
...
"result": {
"id": "<fileId>",
"descriptor": {
...
},
"fileName": "<fileName>"
}
}
Download the translation ZIP File
Download the created translation ZIP file from:<confluence-base-url>/rest/scroll-versions/1.0/translation/adapter/simple/download/<fileId>/<translationProvider>/<fileName>
Both <fileId>
and <fileName>
can be found in the response to our previous request which checks the translation zip file.
Upload the translation ZIP File
Send a post request to:
<confluence-base-url>/rest/scroll-versions/1.0/translation/adapter/simple/upload?spaceKey=<spaceKey>&translationProvider=simple
<spaceKey>
is the key of the space you want to import the file to.Add the file to the request as multipart-form-data from a file-input (see HttpClient Documentation).
When the Translation ZIP file was uploaded successfully, the response will look like this:CODE{ "success": true, "result": { "id": "<fileId>", "descriptor": { ... } }, ... }
The
<fileId>
is needed to import the file.
Import the Translations ZIP File
Send a post request to:
<confluence-base-url>/rest/scroll-versions/1.0/translation/import?spaceKey=<spaceKey>&id=<fileId>&translationProvider=simple
<spaceKey>
and<fileId>
are the parameters from step 3.The response looks like this:
CODE{ "id": "<taskId>", "clusterNo": -1, "started": false, "cancelled": false, "hasFailed": false, "finished": false, "failureMessage": null, "progress": 0, "message": "The task 'Translation.Import' is currently queued.", "resourceLocation": null }
Note that the individual fields may be different, depending on your timing on your server's workload.
To get the current status of the import, send a Get-Request to:
<confluence-base-url>/rest/scroll-versions/1.0/async-tasks/<taskId>?since=<dateTime>
is the current time (as int).
<dateTime>