Download Data of looker dashboard

Hi.. I have a analytics program about the error happened in the production. The input to that program is a csv file which is downloaded  manually by using “Download Data” from one of the bar charts of the looker dashboard. I would like to automate this download process by using python. Could you please help me do this by providing any sample code to do this.

0 8 5,220
8 REPLIES 8

Hi @cdmohans,

You can grab the specific query from the dashboard tile, then run that query and write the result as a CSV. I have listed an example below using our Python SDK. I have a tile on dashboard 1016 called API_TILE. I want to download the data from this tile and write it to a CSV. 

 

import looker_sdk
import csv
import time


from looker_sdk import methods40, models40
sdk = looker_sdk.init40()
me = sdk.me()

tile = sdk.search_dashboard_elements(dashboard_id="1016",title="API_TILE")
tile_query = tile[0].query_id
result = sdk.run_query(query_id=tile_query, result_format="csv")
print(result)
file = open("result.csv", "w")
file.write(result)
file.close()

We also have a similar example in TypeScript that downloads all the individual tiles from a dashboard listed here. Note that the TS example using utils.ts. 

You could create some form of cronjob to run a script to complete this function on a schedule. 

Please let me know if you have any questions.

Thanks,

Eric

Thank you.

Hi, any way we can do this in Java? I know there is no JAVA SDK available in Looker. Any plans to do this in the future?

Hi @tomcribb Would Kotlin potentially work?

I do see a request with our product team to add a Java SDK and I would be more than happy to add your details to that request. I do not know of any specific plans in the near term to add a Java SDK though. 

Please let me know if you have any questions.

Thanks,

Eric




 

Hi @Eric_Lyons ,

Thanks for reply. Kotlin would probably be ok. Have you got Kotlin SDK available?

Regards

The reason I am asking is that i would like to write some automation testing tool. The key part behind it is to have an ability to download dashboards raw data, just like we do via GUI but via API and compare between different instances (Pre-pro & Prod). I thought that SDK would be a way to go for it. I can’t see any API calls that can do it in API docs. Unless i missed something. Regards

@tomcribb Have you seen this by chance?

https://github.com/looker-open-source/sdk-codegen/tree/master/kotlin

Definitely an interesting use-case. I personally would think the SDK would be one of the easier methods, you potentially could create two webhooks and send the dashboards results to some destination and compare the results in java, but you could also do this with the SDK by downloading the data via a simple script. When you say raw data do you mean data in terms of dimensions and measures or actual dashboard LookML?

Thanks,

Eric

Hello Eric,

Thanks very much for your reply. I looked into Kotlin SDK and it looks promising, also i was able to fetch the data i am lloking for to compare via API using Java which also looks promising.

What i meant by raw data, and i am probably not calling it correctly is the data which can be saved in CSV format for instance and is also a graphically  represented for a given dashboard. You can fetch it by selecting the below option:

c514ab36-6c6f-4cf0-b093-55c938c5d5f0.png

Finally the idea with webhooks is actually what i was looking for as the way to export and compare the results. So thanks once again.