Question

Updating Look via API

  • 20 December 2017
  • 2 replies
  • 746 views

Hi all, I have several Looks that I want to update with different filter values via API. In the body of the response, I’ve tried setting filter_config to null, and updating filters with the new filter value. However, the response I’m getting back keeps showing the default filter value, not the desired updated value.


Thanks in advanced!


2 replies

Userlevel 2

Hi @ahuynh,


Inserting a new filter into a look is not going to possible via the update_look(look_id, body) endpoint. In order to do this, we’ll have to use a couple of different endpoints. If you’re working with the interactive API docs, we’ll first hit the Get Look endpoint by entering the Look ID and “query” in the fields section:



Our response body will look like this:


"query": {
"id": 325832,
"view": "order_items",
"fields": [
"orders.count",
"products.category",
"products.count"
],
"pivots": null,
"fill_fields": null,
"filters": {
"orders.user_id": "10"
},
"filter_expression": null,
"sorts": [
"orders.count desc"
],
"limit": "500",
"column_limit": "50",
"total": null,
"row_total": null,
"runtime": 0.198776,
"vis_config": {
"type": "table"
},
"filter_config": {
"orders.user_id": [
{
"type": "=",
"values": [
{
"constant": "10"
},
{}
],
"id": 1,
"error": false
}
]
},
"visible_ui_sections": null,
"slug": "Cm8XHnJ",
"dynamic_fields": null,
"client_id": "T5MxTgH6hco6P2yDSm7ayU",
"share_url": "https://master.dev.looker.com/x/T5MxTgH6hco6P2yDSm7ayU",
"expanded_share_url": "https://master.dev.looker.com/explore/bucket1/order_items?fields=orders.count,products.category,products.count&f[orders.user_id]=10&sorts=orders.count+desc&limit=500&column_limit=50&query_timezone=UTC&vis=%7B%22type%22%3A%22table%22%7D&filter_config=%7B%22orders.user_id%22%3A%5B%7B%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%7B%22constant%22%3A%2210%22%7D%2C%7B%7D%5D%2C%22id%22%3A1%2C%22error%22%3Afalse%7D%5D%7D&origin=share-expanded",
"url": "/explore/bucket1/order_items?fields=orders.count,products.category,products.count&f[orders.user_id]=10&sorts=orders.count+desc&limit=500&column_limit=50&query_timezone=UTC&vis=%7B%22type%22%3A%22table%22%7D&filter_config=%7B%22orders.user_id%22%3A%5B%7B%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%7B%22constant%22%3A%2210%22%7D%2C%7B%7D%5D%2C%22id%22%3A1%2C%22error%22%3Afalse%7D%5D%7D",
"query_timezone": "UTC",
"has_table_calculations": false,
"model": "bucket1",
"can": {
"see_results": true,
"explore": true,
"create": true,
"show": true,
"cost_estimate": true,
"index": true,
"see_lookml": true,
"see_derived_table_lookml": true,
"see_sql": true,
"generate_drill_links": true,
"download": true,
"render": true
}
}

We’ll copy everything below “id” and plug that into the create_query(body) endpoint (we’ll have to add “model” at the top and get rid of the read-only fields, which you can find here, as well as “client_id”). This is where you will modify your filters.


Lastly, we’ll enter our original look ID to the update_look(look_id, body) endpoint, and plug in the id from the create_query endpoint into the “query_id” parameter:


Please let me know if you have any questions about this!


Thanks,


Quinn

Hi @quinn.morrison, just tested it out and it worked perfectly. Thanks for the help!

Reply