How to use Leapwork’s API to export and import flows and maintain a backup?
How to use Leapwork’s API to export and import flows and maintain a backup?
Leapwork allows us to easily test the endpoints in the API and explore the results.
We can maintain the backup of the flows in two ways:
- Export/Import flow
- Backup of the SQLite files
There are two ways to export or import flows in Leapwork:
Manual selection of the flows in Studio and import or export them.
Via the Leapwork public API endpoint
Export Flow: We can use the "Get Export" endpoint by using the Leapwork API to export an automation flow. This endpoint returns a .zip file containing all assets ('Folder', 'Flow', 'DataFile', 'SubFlow', etc.) on the basis of an itemId. The itemId is a unique Id of an element in the asset menu. If an itemId is not supplied, the endpoint will export all assets in the asset menu available in the Controller.
The API can be accessed on the Leapwork Controller machine itself at the following base URL:
"http://localhost:9001/help/index#"
Note: The port 9001 is the default port defined during the installation of Leapwork. If a different port was supplied during the installation, please refer that instead of 9001.
Example:
http://<LeapworkControllerIP or hostname>:9001//help/index#
timeoutMinutes: Define the maximum timeout based on the volume of export objects
targetItemId: Unique identifier (itemId) for an Item in the asset menu.
Access key: To get the Access key
- Open Leapwork
- Go to Settings >> API Access Keys
- Add the API Access Key and Select the Scope as "Import and Export"
- Select the Access Key and click on "Copy".
- Paste it, as defined in the below image:
The Response body returns a URL that can be used to download a .zip file containing exported assets
Sample File Name: Download All_Assets.zip
Import flow: The 'Import' endpoint is used to import an already exported .zip file to the Controller. This endpoint can be used to move flows from one Controller to another. Note that the target item with 'targetItemId' must be a folder.
timeoutMinutes: Maximum timeout for upload
targetItemId: Unique identifier for an item in the Asset hierarchy
.zip file: File to be imported
Response Body
Below is the sample response object
<br>{ "$id": "1",<br> "IsSuccessful": true <br>}<br> |