LookerApi - Get unused looks (last_accessed_at)

api

#1

I’m trying to use LookerApi to find unused Looks and Dashboards. I found the field last_accessed_at and I assumed it was a good one to use for unused content. Although I realised that when a look is in a Dashboard this date is not updated.

Is it expected behaviour? Is there a better way to find unused content through the API?


(Yuriy) #2

Hi @ksilva. We have used Most Recent Query Date Date field from i__looker history table. You use the url below, just replace the <looker_host> with your host name.

<looker_host>/explore/i__looker/history?fields=look.id&f[history.created_date]=before+2018%2F10%2F01&sorts=look.id&limit=500&query_timezone=America%2FNew_York&vis=%7B%22type%22%3A%22table%22%7D&filter_config=%7B%22history.created_date%22%3A%5B%7B%22type%22%3A%22before%22%2C%22values%22%3A%5B%7B%22date%22%3A%222018-10-01T00%3A00%3A00.000Z%22%2C%22constant%22%3A%227%22%2C%22unit%22%3A%22day%22%2C%22tz%22%3Atrue%7D%5D%2C%22id%22%3A5%2C%22error%22%3Afalse%2C%22variant%22%3A%22absolute%22%7D%5D%7D&origin=share-expanded


#3

I’m actually looking for a way to do it using the Looker API, not the Explore.

Thanks anyways.


(Izzy) #4

@ksilva
You might think of it as cheating (and maybe it’s not as performant as a raw query), but a nifty way that I often use the API for more complex things like this is to do exactly what Yuriy suggested, and save that explore as a look that you then hit with the run_look endpoint. That way you can build out your query in the UI and leverage the content data model that we’ve already built, while still getting the results with the API in your preferred format.

If you don’t want to build a look that might clutter your instance, I would honestly probably still use the create/get/run_query endpoints to execute a looker query that would return unused content results.

You definitely COULD just use a raw API call to get_dashboard, which would return the last_accessed_at data for that dashboard as well as the list of looks on it ( the get_dashboard endpoint returns a DashboardElement object that contains a look_id). You’d then have to also hit the get_look or get_all_looks endpoint and get the last accessed date from that. Then, you’d have to check to see if that look ID is present on a dashboard, and if it is, check if the dashboard accessed date is earlier or later than the look accessed date.

So, definitely possible to do it, but why not make Looker do all the hard work and content mapping for you and just execute a look via the api! Lemme know if I can clarify anything about that :smile:


#5

Thanks for the help @izzy. Using the look sounds worth trying, might solve my problem.

I also tried to go through API only for the Dashboards, and this one was fine to use last_accessed_at date. I only had problems with the Looks.

Cheers.