Is there a way to run a look via the api, overriding filters

I’m looking at https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/look#run_look and cannot see a way to specify values for filters;

I’ve also looked at running the query from the look via the api
`GET/api/3.1/queries/{query_id}/run/{result_format}` and `POST/api/3.1/sql_queries/{slug}/run/{result_format}` in this case neither seem to provide a way to override filters either. In addition the latter returns not found from the api, and interestingly the documentation does not specify what the post body should be.

Can someone please help me to find what I’m looking for?

2 3 2,464
3 REPLIES 3

Hi @oliverparaskos,

Right, now you cannot update a filter just on the Look level. Rather, we would have to update filter in the query used in the Look. We can do this by extracting the existing query from the Look, then using the values from that in a new query where we set a filter value. Finally, we can update the original look with the new query.

I have listed an example below using the SDK. I would be more than happy to pass this use-case over to our product team to allow the filters to be updated just on the run Look level rather than the query level.  
 

### GET QUERY ID FROM LOOK
query = sdk.look(look_id=44).query
##CREATE NEW QUERY AND ADD A FILTER
new_query = sdk.create_query(body=models.WriteQuery(model="dogs_of_new_york", view=query.view, fields=query.fields,
filters={"dog_names_of_nyc.count":100}))
### UPDATE LOOK WITH NEW QUERY ID
sdk.update_look(look_id=44,body=models.WriteLookWithQuery(query_id=new_query.id))
###RUN LOOK
result = sdk.run_look(look_id=44,result_format="csv")
print(result)

There are a few other examples or methods listed here: 

https://community.looker.com/looker-api-77/update-look-with-filters-in-python-12589

Please let me know if you have any questions.

Thanks,

Eric

@Eric_Lyons 

Hi, I have a question about the use case to use run a query API and run a look API. Why would I choose one over the other - other than I need Query id vs Look id as an input?

Thanks

Hi @oliverparaskos,

Right, now you cannot update a filter just on the Look level. Rather, we would have to update filter in the query used in the Look. We can do this by extracting the existing query from the Look, then using the values from that in a new query where we set a filter value. Finally, we can update the original look with the new query.

I have listed an example below using the SDK. I would be more than happy to pass this use-case over to our product team to allow the filters to be updated just on the run Look level rather than the query level.  
 

### GET QUERY ID FROM LOOK
query = sdk.look(look_id=44).query
##CREATE NEW QUERY AND ADD A FILTER
new_query = sdk.create_query(body=models.WriteQuery(model="dogs_of_new_york", view=query.view, fields=query.fields,
filters={"dog_names_of_nyc.count":100}))
### UPDATE LOOK WITH NEW QUERY ID
sdk.update_look(look_id=44,body=models.WriteLookWithQuery(query_id=new_query.id))
###RUN LOOK
result = sdk.run_look(look_id=44,result_format="csv")
print(result)

There are a few other examples or methods listed here: 

https://community.looker.com/looker-api-77/update-look-with-filters-in-python-12589

Please let me know if you have any questions.

Thanks,

Eric

Hi Eric, just to get some attention on the topic, we also had this problem and had to switch to update a look before running it. So, we want to chip in, we would be happy to set filters on run_look 🙂