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
- Run create_dashboard_filter endpoint, noting the filter name.
- Run get_all_dashboardelements to get an array of all tiles on the dashboard.
- Run get_dashboard_element and copy any existing applied dashboard filters in the "listens" array.
- Run update_dashboard_element by pasting in the existing filters to the "listens" array, then add your new filter to this array.
- Repeat steps 3 and 4 for any other elements returned in step 2 that you would like to have the new filter
Creating the Filter
Use the create_dashboard_filter endpoint: https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/dashboard#create_dashboard_filter
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:
Applying the filter
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_dashboardelements 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_dashboardelement 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_dashboardelement 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.