Forum Discussion
bluemetrics
09-22-2022Cloud Apps
Hi bpeikes,
Our team developed a Python API for Sisense that makes a lot of the tasks you described faster and automated. For example, the code below could be used to perform the tasks described for datamodels:
from sisense import Sisense
import json
host = 'https://your_sisense_url'
token = 'your_api_token'
elasticube_name = 'Name of the elasticube you wish to duplicate'
sisense = Sisense(host, token) # Connection to Sisense
# sisense.datamodel.list() # Lists datamodels, good for testing the connection
# sisense.elasticube.all() # Same but for elasticubes on Windows
# Get the cube by it's name and uses it to get the datamodel
cube = sisense.elasticube.get(elasticube_name)
model = sisense.datamodel.get(cube.oid)
# Exports the datamodel to a JSON file
filepath = 'Model.smodel'
model.do_export(filepath)
# Imports the JSON file for editing
with open(filepath, 'r') as file:
smodel = json.load(file)
# Change model's properties (some connection parameter, for example)
smodel['datasets'][0]['connection']['parameters'] = ...
# Exports the altered JSON
with open(filepath, 'w') as file:
json.dump(smodel, file, indent=4)
# Imports the altered datamodel as a new one in Sisense
sisense.datamodel.do_import('New Datamodel', filepath)
There are also very similar functions that allow you to do the same with dashboards.
To use the Sisense API for Python, you will need to install it using pip as below:
pip install sisense
There's also documentation on getting started using the Python library: Sisense API — sisense documentation
If you have any questions don't be afraid to reach us out!
Best regards,
BlueMetrics