Copy dashboard from one folder to another and turn looks into look-less tiles automatically

This code is a bit of a work in progress, as I have it set to work with only a single look at the moment. 
Having said that, the logic works, so we would just need to work with the syntaxing.

#Install Looker
! pip install looker_sdk

#Import packages
import urllib3
import looker_sdk
import json
from looker_sdk import models, error


#setup environment
os.environ['LOOKERSDK_API_VERSION']='4.0'
os.environ['LOOKERSDK_BASE_URL']='XXXXX'
os.environ['LOOKERSDK_CLIENT_ID'] = 'XXXXX'
os.environ['LOOKERSDK_CLIENT_SECRET']='XXXXX'

urllib3.disable_warnings()
sdk = looker_sdk.init40()

#Grab the query id of the Look/s in the original dashboard
dashboard = sdk.dashboard(
    dashboard_id="1")
query_id = dashboard["dashboard_elements"][0]["look"]["query"]["id"]

#Create a new dashboard in the folder you want to
create_dashboard = sdk.create_dashboard(
    body=models.WriteDashboard(
        title="api_test",
        folder_id="8"
    ))

#Grab the id of the newly created dashboard
new_dashboard = sdk.search_dashboards(
    title="api_test")
dashboard_id = new_dashboard[0]["id"]

#Add the Look as a look-less tile to your new dashboard
update_dashboard = sdk.create_dashboard_element(
    body=models.WriteDashboardElement(
        dashboard_id=dashboard_id,
        query_id=query_id,
        type="vis"
    ))

#Voila!

The coding itself is explained in the comments, however the idea behind this is that when we manually copy a dashboard with looks attached in the Looker UI, those looks also get moved into the new folder.

It is fairly common that we don’t actually want to copy those, and manually converting can get tiresome if this is a standard practice at your company.

Next steps would be adding some loops so that everything will work with multiple queries, and also fleshing out with dashboard text-tiles/look-less tiles also being transferred!

0 0 547