(Just spreading some awareness, to help save others time in the future. Many thanks to my wonderful Looker Support representative, Annie.)
Copying a look was confusing at first. I had assumed I could just take the `look()` endpoint to grab the body of the existing look, and then use the `create_look()` endpoint to create a copy (and adjust certain inputs if needed, like filters).
Unfortunately, `look()` doesn’t actually return a JSON response. It returns something called a “LookWithQuery” object; this object is JSON-like, but it also has other non-JSON-y objects – like “Query”. On the other hand `create_look()` requires a JSON-dict input.
So, you can’t just put the response from `look()` into the body of `create_look()`.
What you need to do is extract the “query_id” and “space_id” from from the LookWithQuery object.
Then, create a new JSON-dictionary with these fields, add a “title”, and add whatever other fields you want to adjust (like “filters”).
Pass this to `create_look()` instead.
import json
import looker_sdk
from looker_sdk import models
sdk = looker_sdk.init31("looker.ini")
look_object = sdk.look(look_id = 1) # or whatever look_id you'll copy
#
# or, you might need to use: sdk.look(look_id = 11250).__dict__
#
# the hidden attribute __dict__ (double underscore) produces the JSON version of that object: https://community.looker.com/looker-api-77/update-look-with-filters-in-python-12589
query_id = look_object["query_id"]
space_id = look_object["space_id"]
json_query = {
"title": "SDK Copy of Look",
"query_id": query_id,
"space_id": space_id
}
y = json.dumps(json_query)
sdk.create_look(y)
Miscellaneous Notes: