Awesome API
With the recent announcement that version 4.0 of the Looker API has left beta and moved to General Availability, now seems like a good time to talk about the API!
Looker’s API is pretty comprehensive and as a rough rule of thumb you can use the API to do almost anything you can do in Looker’s web UI. With the recent addition of the API Explorer application you can even browse and interactively run API endpoints from within Looker itself without having to get your hands dirty writing any code and without having to generate or manage API credentials.
I’m not going to spend time talking about scripting other than to say that I generally use Python and the looker_sdk
package to write simple one-off scripts as it’s a very portable and accessible language, and Looker’s API examples provide starting points for some commonly-used endpoints.
If you’re comfortable using a command line, it can be handy to have an iPython REPL shell open so you can interactively use the API and write simple loops etc.
Here a few simple but very effective things you can do with the API, either via the API Explorer or with some simple scripting.
- See detailed information about queries, Looks, Dashboards, and most other Looker objects. For queries this can be useful if users bookmark links to Explore queries but the LookML has since changed.
⚠️ One caveat here - the last accessed time for Looks reflects when they were last accessed as a standalone Look, so if you’re deleting dashboards be sure to check the last accessed time for the dashboard too.
- Get and expire users’ Looker sessions - handy to force them to log in again e.g. to apply new permissions via an external system.
- Find users with a particular group/role and assign them to another group or role - great for tidying up your permissions on a busy Looker instance.
- Get user attribute values assigned by different groups, and use their rank to determine which value is actually applied for a user.