Last tested: Mar 30, 2020
The good news: creating the filter is very easy!
The bad news: applying it to tiles is much more involved
Use the create_dashboard_filter endpoint: https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/dashboard#create_dashboard_...
For more complex filter syntax, I'd recommend creating an example filter then using the endpoint to get the filter and see what the API returns. An example of a simple call:
This part is a bit more involved. Note the name of the dashboard filter we just created, as we will be using it in the final API call.
First, we will want to get a list of dashboard elements (tiles) on the dashboard that we created the filter on using this endpoint: https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/dashboard#get_all_dashboard... This will return an array of dashboard element ids to update.
Now, it is important to call get_dashboard_element: https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/dashboard#get_dashboardelem... This will return lots of info, but search for the "listens" array and copy that. This array is the list of filters already applied to this tile, we will need to preserve that when adding this new one. Example output to look for:
If this array is empty, that is fine, it means no filters have been applied to this tile yet.
From here we will call update_dashboard_element: https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/dashboard#update_dashboarde... The body of the call will look like so:
In this example, "created" and "created_2" were already applied, so I pasted them from the get_dashboard_element call. I then added the comma and the next object for the new filter.
Congratulations! You have now added your new dashboard filter to a tile on your dashboard. Repeat for any other tiles in the get_all_dashboardelements call you would like this applied to.
This content is subject to limited support.
Hi, im trying to do what is described above, but im having difficulties finding that ‘listens’ array mentioned above. Also the screenshots are not available, so that does not really help.
I tried with python sdk 3.1 and 4.0.
What am I missing here?
Hi Ryan,
Can you reupload the screenshots. We are not able to see them
@akhilsai there is an updated version of this page, see https://help.looker.com/hc/en-us/articles/4420191525651-How-To-Create-a-Dashboard-Filter-Through-the...
I also got some Python SDK warnings in my IDE, but it actually does execute the api call with the outcome I want:
@Gijs1 : Thanks for your inputs.
One Question I have is, When we select the filters in the dashboard. Do those filter values capture?
@Gijs1 : Thanks for your inputs.
When we select the filters in the dashboard. Do those filter values capture?
I dont understand your question (and im not that known with Looker).
Before I call the code to create a DashboardElement (and let that element listen to the filters), I already created the filters needed on this dashboard, with the exact same name I use in the code above:
response = sdk.create_dashboard_filter(
body=ml.WriteCreateDashboardFilter(
dashboard_id=str(_dashboard_id),
name='source',
title='source',
type="field_filter",
dimension='tags.source',
model='star_schema',
explore='invitations_and_responses',
required=False,
))
@Gijs1 :
We have a requirement like below,
The below are the things we implemented
What we want is the below
Sorry I cant help with that. This topic is to use the SDK to create a dashboard within Looker, which is different from what you are asking.
Sorry I cant help with that. This topic is to use the SDK to create a dashboard within Looker, which is different from what you are asking.
No Issues. Thanks for you help