Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I've got what seams like a simple challange. Return all the expressions in an Qlik Sense SaaS application using Python and the API
I've been playing around with different options but just cant get over the final hurdle
The Engine API (https://help.qlik.com/en-US/sense-developer/April2018/apis/EngineAPI/index.html) appears to have methods that would possibly do the job.
I've written this code (the class boiler holds my OAuth connection) ...The first two methods work (OpenDoc and OSName) but the others return errors (Method not found). I'm guessing they can't be called directly and I'm missing some syntax somewhere.
Any help from the pro's would be apprecaited
rpc_session = boiler.client.rpc(app_id='3c06ba8a-c5ea-4bf2-b0eb-e014915100bb')
with rpc_session.open() as rpc_client:
## Methods from the Global Class work
app = rpc_client.send("OpenDoc", -1, '3c06ba8a-c5ea-4bf2-b0eb-e014915100bb')
osname = rpc_client.send("OSName",-1)
## Methods from other classes return an Exception: Method not found
test = rpc_client.send("GetObject", -1, 'FkeYd') # <-- This would work with app.get_object('FkeYd')
test = rpc_client.send("GetInfo", -1)
test = rpc_client.send("MeasureList", -1)
I'm not familiar with working with the engine API through Python, but as @rwunderlich mentions, you need to use the correct handle for your calls to ensure you call the app methods for an opened app. Is the the '-1' in your calls a handle? In that case you are trying to call the "GetObject" method on a the Global scope, and there is no such method there.
I wrote a set of blog posts on how the engine API works a couple of years ago where I among other things wrote about handles. Maybe they could be useful for you:
Those are methods in the App object. As you indicated in your comment, you need to call them from app.
-Rob
I'm not familiar with working with the engine API through Python, but as @rwunderlich mentions, you need to use the correct handle for your calls to ensure you call the app methods for an opened app. Is the the '-1' in your calls a handle? In that case you are trying to call the "GetObject" method on a the Global scope, and there is no such method there.
I wrote a set of blog posts on how the engine API works a couple of years ago where I among other things wrote about handles. Maybe they could be useful for you:
Thanks Øystein, I've bookmarked them and will read through.
-1 is the handle. Honestly I'm addrift with that termanology so will read up on that more. I can see there's a post dedicated to it.
I have developed extensions before in javascript so have seen and used the hypercube. I'm guessing once I know the object id I could take a peek at those internal qMeasure values.
I'm off work today, but will take a good look on Monday. Thanks
Hi Rob., good to hear from you. Hope you're doing well!
I did take a peek at all the app methods using the help function. Although there's a lot of thing there such as GetObject I couldn't find anything that brought back the expressions.
This morning I had another look at the CLI and could see the qMeasureInfo there. Although even with vebose selected I can't really see whats going on so can't translate back to Python... Any ideas?
Hi Richard,
I'm not familiar specifically with python syntax, but here is the general path. The CLI I'm sure does several engine calls under the hood to provide the information shown in your screenshot. You need to navigate
global > app > chartObject > properties (or layout)
Something like:
app = rpc_client.send("OpenDoc", -1, '3c06ba8a-c5ea-4bf2-b0eb-e014915100bb')
chartObject = app.get_object("FkeYd")
props = chartObject.get_properties()
layout = chartObject.get_layout()I'm not sure those methods are available but I'm guessing they may be.
I note that the folks at Arc Analytics @AustinSpivey have posted a blog about using the python qlik-sdk. The post's example is very close to your requirement.
A really great developer tool from @Øystein_Kolsrud is the Qlik Explorer for Developers https://community.qlik.com/t5/Qlik-Sense-Documents/Qlik-Explorer-for-Developers/ta-p/1949809
The tool lets you explore the structure of an app's metadata and is useful for understanding how to navigate properties and layout.
-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com
Thanks very much @rwunderlich and @Øystein_Kolsrud you both really helped.
final code:
rpc_session = boiler.client.rpc(app_id='3c06ba8a-c5ea-4bf2-b0eb-e014915100bb')
with rpc_session.open() as rpc_client:
## Methods from the Global Class work
app = rpc_client.send("OpenDoc", -1, '3c06ba8a-c5ea-4bf2-b0eb-e014915100bb')
print(app)
object = rpc_client.send("GetObject", 1,"vXbVJJ")
print(object)
props = rpc_client.send("GetProperties", 2,)
print(props)
layout = rpc_client.send("GetLayout", 2,)
print(layout)
app_allinfo = rpc_client.send("GetAllInfos", 1)
print(app_allinfo)
The chapter about Handles made the difference in my understanding and the posts where very helpfull overall to follow.
I can see with the return from GetAllInfos I can peek at each objects layout in a loop and retrieve the Measure information.