Knowledge Drop

How To Create a Dashboard Filter Through the API

  • 15 June 2021
  • 9 replies
  • 586 views

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

tl;dr

  1. Run create_dashboard_filter endpoint, noting the filter name.
  2. Run get_all_dashboardelements to get an array of all tiles on the dashboard.
  3. Run get_dashboard_element and copy any existing applied dashboard filters in the "listens" array.
  4. Run update_dashboard_element by pasting in the existing filters to the "listens" array, then add your new filter to this array.
  5. 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:

Screen Shot 2020-03-30 at 2.10.48 PM.png

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:

Screen Shot 2020-03-30 at 1.36.35 PM.png

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:

Screen Shot 2020-03-30 at 2.15.36 PM.png

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.                

 

 


9 replies

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-API-Community-

I also got some Python SDK warnings in my IDE, but it actually does execute the api call with the outcome I want:

 

@Gijs : Thanks for your inputs.

 

One Question I have is, When we select the filters in the dashboard. Do those filter values capture?

@Gijs : 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,
))

 

@Gijs :

We have a requirement like below,

  • We need to send bulk data to Google Spreadsheet after invoking an action from looker.

 

The below are the things we implemented

  • We are able to send the whole data to Google Spreadsheet but not filtered data.

 

What we want is the below 

  • We are looking for an looker SDK where we can captures filter values. 

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

Reply