Using Looker API to copy dashboards

Hi there,
I am trying to create a simple python script to copy dashboards (these are user-defined dashboards), as well as their underlying Looks.
Basically I am reading the info from the “source” dashboard, and using the create_dashboard and/or update_dashboard API calls.
I am being stumped by a couple of issues:

  1. I can’t seem to get the references to Looks and layouts into the “copied” dashboard. I just end up with an empty dashboard. When I look at the Dashboard data structure, I notice that dashboard_layouts and dashboard_elements are marked as readonly, so it makes sense that it doesn’t use this info when creating/updating the dashboard. But is there a way to do this in the API?
  2. I can’t see how to use the API to copy dashboard-level filters. The dashboard-level filter info doesn’t seem to appear anywhere in the dashboard data structure?

Thanks for any clues you can provide…

2 Likes

Hi @mjoy_te!

Regarding your first point - I’ve tried running the same process as yourself and I’m getting exactly the same result. I’ll try few different things to confirm whether there is another method of achieving it or it possibly is a bug on our side.

When it comes to dashboard filers - I can see the dashboard(dashboard_id) endpoint returns information about all linked filters in the "dashboard_filters" parameter. It’s important that the dashboard has a filter linked to the desired elements with the default value set.

I’ll keep you posted once I find out more about the create_dashboard(body) endpoint.

Thanks Aleks, I’ll have a close look at the filter stuff, maybe I am doing something incorrectly.
Please do keep me posted about point #1 (references to looks and layouts) - this is currently a blocking issue for us so it would be good to know if there is a workaround or if we will need to go about it differently.

Hi @mjoy_te!

It turns out the dashboard_elements and dashboard_layouts fields of the dashboard type are read-only in the create_dashboard method. This means they are ignored when passed to create_dashboard API call. I’ve tried to use the update_dashboard post create_dashboard but the child lists are also read-only in that method, so it wont work either.

After discussing it with the engineering team, currently there is no way to copy dashboards via API. However, I’ll pass that request to our product team for you so it’s considered in future releases.

OK thanks for your reply. We certainly look forward to seeing this in the API…

1 Like

Just to add something here, I think I’ve figured out how to do this with the URL based API. I don’t know if it’s possible with the SDK.

For each look you want to add to a dashboard, you can send a POST request to the endpoint /api/3.0/dashboard_elements. It’s body should contain a look_id, a dashboard_id, and a type. The creation of this will add the look to the dashboard, and it will now show up when the dashboard is fetched again.

That makes copying a bit more complicated, but should allow you to at least add the looks from the old dashboard one by one to the new dashboard.

I couldn’t find it documented anywhere, but I guessed from the naming convention and it worked. I presume the same would work if you wanted to create a dashboard_filter object (a POST request to /api/3.0.dashboard_filters) or a dashboard_layout object (a POST request to /api/3.0.dashboard_layouts).

Hope that helps. I certainly struggled with it for a while.

I have created a ruby script which copies a dashboard to any other space, using your thoughts @Tull_Gearrealdas a starting point - thank you!

If others are interested in doing this highly unsupported thing, I could look into sharing it. :slight_smile: Let me know if so…

Hey Aaron,

Could you please share the script with me so that i can refer that. Thanks in advance.

1 Like

I’m also interested in this.

Specifically, I’d like to save user defined dashboards as lookml and store in git.

GZR, a command line tool for Looker, will allow you to do this outside of the UI.

Hi @aleks – With API 3.1 being rolled out with Looker 6.12, I was wondering where this feature request stands. Being able to copy dashboards via the API will solve a huge missing feature in our user flow.

The command-line / scripting utilities solve the need for internal use-cases but not user-facing needs of an analytics feature built on Looker.

Hoping that this gets prioritized soon. Please let me know if there are any new work-arounds introduced with 3.1 that involve making multiple calls, etc. Thanks!

1 Like

@aleks @shiggins

Any update on this? Looks like the original request to copy a dashboard via the Looker API was submitted on April of 2017.

We have a use case that requires dashboards to be copied into different spaces and doing it the manual way is not possible (you can’t move a dashboard into an embed group in the ui because they don’t show up). I created a Python script to do all of this for me only to find out that the the create_dashboard method doesn’t work due to all the readonly fields (as mentioned above).

I looked at GZR but don’t see anywhere that supports copying a dashboard. If I had the power to Copy a Dashboard (just like you do in the UI), then we’d be good to go here.

Now that it’s August of 2019, and a new API has been delivered (3.1), what’s the update on the ability to copy a dashboard? Is this a feature that Looker will not implement?

No new endpoints have been released for explicitly copying a dashboard. You can use GZR to copy dashboards. A basic flow would be the below:

Export
gzr dashboard cat 1004 --host company.looker.com --client_id 123abc --client_secret 789xyz > dashboard1004.json
Import
gzr dashboard import dashboard1004.json 101 --host company.looker.com --client_id 123abc --client_secret 789xyz
(‘1004’ being a dashboard id, 101 being a target space id)
It should be straight forward enough to wrap these into a single Python (or any language) script.

1 Like

Thanks @shiggins!