Question

How can I request dashboard by API with time range filters?

  • 4 February 2021
  • 1 reply
  • 538 views

Hi, I’m trying to generate PDF of my dashboard via Looker API in python. How can I set filters with time range?

I’m using the looker_sdk package and I know how to set filter with only one value, like ‘Date’: ‘2021-01-01’, but what is the code if I want to run the dashboard for a period of time, for example, from ‘2021-01-01’ to ‘2021-02-01’? Below is what I chose in the dashboard views.


Below is my code and the ‘Date’ part has an error.

dashboard_title = 'My Dashboard'    # dashboard title
pdf_style = 'tiled' # PDF style
pdf_width = 1000 # PDF pdf_width
pdf_height = 842 # PDF pdf_height
dash_filter = {'Brand': 'ABC',
'Account': 'Client - ABC',
'Season':'Spring 2021',
'Date': 'is in range, 2021-02-01, 2021-04-01'
} # {"filter1": "value", "filter2": "value",...}

 

Please let me know how can I solve the problem, thanks!


This topic has been closed for comments

1 reply

Hey Claire - thanks for reaching out! I believe you’ll want to treat the filter date range value as a single string.

 

for example: 

{'my_date_filter_name': '2021-02-01 to 2021-04-01'}

The date specific filters value syntax will correspond to the syntax in our Date and Time Filter Expressions doc. 

 

Also a troubleshooting tip - a good way to find out the right syntax to replicate queries using the API would be to:

  1. Create the query from the UI and save as a Look 
  2. Use the `/look` endpoint to grab the metadata on the query 
  3. Grab the query object from the response
  4. Get at the filters parameter from the query object
my_look = looker_sdk.look('123') #step 2
my_query = my_look.query #step 3
query_filter = my_query.filter #step 4