Forum Discussion
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
- bpeikes09-23-2022Cloud Apps
That looks great! How do you use the module to get your api token? Looked at the docs and it wasnt clear?
I know we can get one from the web ui, but I’d rather the people using the script to just need their username and pwd.
- bluemetrics09-23-2022Cloud Apps
Currently, we don't support username and password authentication. This will come up on soon. If you want, you can create your own function or fork the project on GitHub. The function would look something like:
import requests def login(username: str, password: str) -> str: data = {'username': username, 'password': passoword} headers = { 'accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded' } response = requests.post('https://your_app_url/api/v1/authentication/login', headers=headers, data=data) response.raise_for_status() content = response.json() if content['success']: return content['access_token'] raise ValueError(content['message'])
I hope this helps.
Best regards,
BlueMetrics