Question

Looker API Dashboard Run

  • 10 June 2021
  • 4 replies
  • 181 views

From API, how do we achieve similar behavior as Dashboard run we do from UI? For e.g.

https://abc.looker.com/dashboards/2856?Date=1 months ago for 1 months&filter_config={"Date":[{"type":"past","values":[{"constant":"1","unit":"c_mo"},{}],"id":1}]}

 

I found one related post here, but did not quite get the part of “Then applying the dashboard filters to each element’s query and running them separately. Afterwards all the elements need to stick back together. ”

How can we run a dashboard alongwith filters via API?

 

 


4 replies

Following. I think I understand the proposed solution in https://community.looker.com/looker-api-77/dashboard-api-10802, but I’m hoping that over two years later, there is a better way. 

This is something we will need to do quite frequently to compensate for Looker’s lack of pdf formatting options. 

Following. I think I understand the proposed solution in https://community.looker.com/looker-api-77/dashboard-api-10802, but I’m hoping that over two years later, there is a better way. 

This is something we will need to do quite frequently to compensate for Looker’s lack of pdf formatting options. 

I agree with you @KatieK , I am also facing the same issue. Wondering if there is a better way to do this.

Userlevel 3

There currently isn’t a singular “run_dashboard” endpoint - as the linked post implies you have to loop each element’s query individually. I can give that solution a bit of color though, it’s not quite so bad as it sounds. I’m using the PythonSDK for this example because it’s more readable. 

 

 

# dash_id is the dashboard we want to get elements of      
# search_dashboard_element returns a dictionary with .. 
# a result_maker object. that’s the object we want

data = sdk.search_dashboard_elements(dashboard_id=dash_id)

# here we’re just looping through elements to get the object we want

numelemnets = len(data)
for x in range(numelemnets):
element_query_body = data[x].result_maker.query
element_query_body['limit'] = -1   

# there’s definitely a better way to do this 
# basically, we only need certain parameters from the element body 
# list of required parameters is parameters_needed 
# then the try catch matches keys in element body to that list 
# probably dont need this step to be honest

parameters_needed = ['model','view','fields','filters','sorts','limit','query_timezone']
final_body = {}
for y in range(listlen):
try:
new_el = element_query_body[parameters_needed[y]]
except:
i+=1
else:
final_body[parameters_needed[y]] = new_el

# this is the final result of a tile’s query 
# from here, you can write resultset to a new file 
# then the next loop can begin

resultset = sdk.run_inline_query('csv', final_body)

 

Can someone make it brief and set parts, the steps order, for implantation of the dashboard API?

Reply