I’ve been trying to run a look using the API, edit the values of existing filters, and return a png graph that I can use. No matter how I try, I can’t seem to run the look with the changes to the filters applied. Is there a specific way this is supposed to be done?
Hello
In order to change the filter values on a look via the API, you can
- Use the get look endpoint to get the query for a look
- Get the query id for that Look
Get the query for that query id- Update the filters on that query
Create a new query in Looker
Update the look with that new query
Here is some example Ruby code written by our very own
require 'looker-sdk'
LOOKER_ID = ENV['LOOKER_ID'],
LOOKER_SECRET = ENV['LOOKER_SECRET']
LOOKER_PATH = 'https://company.looker.com:19999/api/3.0'
looker = LookerSDK::Client.new(
:client_id => LOOKER_ID,
:client_secret => LOOKER_SECRET,
:api_endpoint => LOOKER_PATH
)
# get look, here look id 32
my_look = looker.look(32)
# get query id for look
my_query = looker.query(my_look.query_id).to_attrs
# set new filters, here update the value for order_id
my_query[:filters] = {:"order_items.order_id" => "<567"}
# remove the client id!
my_query[:client_id] = {}
# create a new query
my_new_query = looker.create_query(my_query)
puts "New Query ID: " + my_new_query[:id].to_s
# update look with new query
my_look = looker.update_look(32, :query_id => my_new_query[:id])
puts "Updated Look Query ID: " + my_look[:query_id].to_s
if my_new_query[:id] == my_look[:query_id]
puts "Success!"
else
puts "Fail again, fail better"
end
Once the look is updated, you can follow the steps in this discourse post to render that Look as an image. If you have any questions about this, let me know!
Ryan
I’m doing it in python currently.
My issue with creating a new query is that it seems to ruin the visualization options. Not sure why, but it produces errors if you try to run visualizations after updating through the API, even in the web version.
Hi
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.