I like how the /query url works and you can download all of the SQL for each query. Handy. I’m trying to figure out the utility of the /dashboard/ API. I would sort of expect it to be similar to how you could import/build a dashboard using JSON parameters. But, I’ve looked at the dashboard output, and while I can see name, creator, user, etc. I don’t see any information about how it configures an actual visualization for a dashboard. Is there meant to someday be a separate API call for visualizations, or am I just missing it? All I can see is a big list of numbers in ‘layout’ which appears to be describing the layout of a dashboard, but no real useful way to take that information and build a dashboard in another Redash instance.

Ideally, the way to dump the visualizations in JSON format would be readily available so that it would be easy to recreate a dashboard on another instance, referencing the right queries, x axis, y axis, visualization type, groupings, stacking, etc.

Thoughts?

If I just print out the json, I notice that all of the ‘widget’ values are empty, which is a further puzzle:

examples/dashboard_export.py --redash-url https://192.168.10.139/redash --api-key ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’ | grep widgets
‘widgets’: None},
‘widgets’: None},
‘widgets’: None},
‘widgets’: None},

(I patterned dashboard_export.py from query_export.py)

Can you share the contents of export_dashboard.py? Otherwise we can only guess…

The dashboards endpoint isn’t going to spit out everything you need to reconstruct a dashboard because that would mean duplicating data. The building blocks of Redash are queries. Queries can have visualizations. Dashboards contain widgets. Widgets may either be text boxes or references to visualizations. So a dashboard object is really just a list of references to visualizations and info about how to position those widgets on a screen.

To fully re-assemble a dashboard you will need to fetch its definition (position info and any text box widgets), then duplicate the queries and their visualizations which are referenced from the dashboard object. This is how the migration script works.

I can, but it’s a minor variation of export_query.py from redash_toolbelt, it just uses the dashboard API instead of query to collect the json.

def save_dashboards(dashboards):
for dash in dashboards:
filename = ‘dashboard_{}.json’.format(dash[‘id’])
pprint(dash)

The thing I’m interested in is the widget definition, fields, etc. But, I don’t see a way to get the widgets out. The dashboard itself is secondary, it’s the definitions to build the widgets that I’d love to be able to just export use to rebuild.

Like so:
examples/dashboard_export.py --redash-url https://192.168.10.139/redash --api-key 'XXXXXXXXXXXXXXXXXXXXXXXX' | grep -c widgets 82 [doug@dh-sfdemo redash_toolbelt] examples/dashboard_export.py --redash-url https://192.168.10.139/redash --api-key ‘XXXXXXXXXXXXXXXXXXXXXXXXX’ | grep widgets | grep -cv None
0

82 widgets definitions from the dashboard json, but all of them are None for some reason.

Please share your dashboard export script. What you describe is totally possible (it’s how the semi-official migration script works). But it sounds like your version has a bug that corrupts the widget definition and makes it None (the API cannot return a None definition for a widget :wink:) . If you share your script we can find the bug.

Here’s the minimally complete version:

def get_dashboards(url, api_key):
    dashboards = []
    headers = {'Authorization': 'Key {}'.format(api_key)}
    path = "{}/api/dashboards".format(url)
    has_more = True
    page = 1
    while has_more:
        response = requests.get(path, headers=headers, verify=False, params={'page': page}).json()
        try:
            dashboards.extend(response['results'])
            has_more = page * response['page_size'] + 1 <= response['count']
            page += 1
        except KeyError:
            pprint(response)
            return []

    return dashboards

def save_dashboards(dashboards):
    for dash in dashboards:
        filename = 'dashboard_{}.json'.format(dash['id'])
        pprint(dash)

def main(redash_url, api_key):
    dashes = get_dashboards(redash_url, api_key)     
    save_dashboards(dashes)

Thanks. The problem here is the script never pulls the complete dashboard object from the API. It’s using the “list dashboards” endpoint (api/dashboards) which only includes information needed to display a list of dashboards. You can get the full dashboard object from api/dashboards/<url-slug>.

Okay, thanks. I plan on contributing this back to the toolbelt when it’s working because I think it’s very useful for all kinds of purposes.