How do I use the Looker API to run an inline query, but against a Look instead of a model so that the query can be run against a PDT ?

  • 19 April 2022
  • 1 reply

I’m trying to implement a use case where there’s a multi tenant app and users are performing actions against it that result in data being retrieved from the Looker API. We have a Look set up for this data retrieval use case. And we use a PDT with the Look to make the queries as fast and cheap as possible, since they execute against BigQuery. In the future, we plan to save the PDT in PostgreSQL instead of BigQuery because we know the aggregated form of the data in the PDT is small enough to fit in PostgreSQL.

I’m struggling to implement the part where I call the Looker API. The Look needs to support filtering. We added filters to it, and this works fine when clicking around the UI to query it given different filter values. But with the API, in the run_look method, there isn’t a way to set the filter values. I found this page which describes a workaround:

The workaround is to treat the Look as a mutable resource instead of immutable resource. Instead of querying it multiple times, specifying filters each time just for each query, you mutate the Look by editing its query, editing the filters of that query, then saving the new state of the Look after that edit. Then you run the Look using run_look.

I see how this solves that use case, but this wouldn’t work for our multitenant use case. Multiple users for each of our customers may be browsing the app at the same time, triggering these Looker API calls, and multiple customers may have their users browsing the app (we use customer as a filter to make the single Look support all of our customers). So we would have to implement some sort of locking mechanism to make this API call have a concurrency of 1, so that one user’s filter values don’t overwrite those of another user while a query is in progress.

I found the API method run_inline_query which appears to be what I’m looking for:

It would allow me to specify a query, including its filter values, every time. But I don’t see “look_id” in that method’s parameters. I want to run a fresh query against the Look we made each time, not against the model and view. It’s important that it’s the Look and not the model because we need to leverage the PDT feature so that we’re querying a small amount of data instead of the raw data of the model each time.

Is there a way to use run_inline_query for my use case? Or is there some other API method I should be using instead? Or, is it even possible to use the API for this use case?

This topic has been closed for comments

1 reply

I think I may have figured out how to do this. I started following that workaround where you modify the query to see what would happen anyways and that led me to believe queries are more flexible than I thought they were. I was able to retrieve the query associated with my Look, modify it in my SDK code, and then run the query (without saving it back to the Looker instance, which I’m trying to avoid) by using run_inline_query:



let response = await sdk.ok(sdk.look(<redacted>));


// Use the query associated with the Look. Edit it to set the filters.

const query = response.query;

delete query.client_id; // not needed for API use

query.filters["<redacted>"] = "<redacted>";


// Use edited query in run_inline_query

response = await sdk.ok(sdk.run_inline_query({

body: query,

result_format: 'json',


console.log("response (first item only):", response[0]);



(And I see the same data I saw in the UI with the filter set)


Still curious if there’s any feedback from Looker staff on whether this is the recommended approach for this. So far this seems promising.