Exporting Dashboard

Hi All, I need to export the entire dashboard to use it else where. Is this possible?

If not, I’ve tried to export at query level but I’m getting errors.
I navigated to my query, I clicked on ‘show API Key’

Copied the API Key and query URL and did this two lines of code:
pip install click requests and
python query_export.py --redash-url "https://app.redash.io/<slug>" --api-key "<api-key>"

The return I got was:
ValueError: No JSON object could be decoded
and if I used the link from the pop up window, I get:
KeyError: ‘results’

Just to check… by “export the entire dashboard”, are you meaning make it public so people without a Redash account (on the server) are able to view it, or are you meaning something else? :smile:

Oh. No, not making it public. I would like to save the queries as a file. I am planning to use it else where. Also, I have parameters, I realised I can’t set the dashboard to ‘allow public access’

Is there anyway to go about doing this? Open to other suggestions as well. Thank you

The query text (SQL) or the resulting visualizations?

Yes, this is something we’re working to support in this Pull Request:

The resulting visualisations.

Oh. Like save the result as (say) PDF, including the generated images?

I’m actually trying to export the dashboard. I want to transport my data to a different platform.
I’ve tried API requesting, (as in my initial problem) using the given script.

At present, the API doesn’t return nice, clear error messages about why it’s not finding or returning the requested data. That could be better. :frowning:

What is the text fragment you’re using for the <slug> piece?

Experimenting a few days ago with a local instance in a VM, the API was responding properly when I left off the slug piece completely. eg:

# ls -al
total 8
drwxr-xr-x. 2 root root   29 Jul  7 20:30 .
dr-xr-x---. 8 root root 4096 Jul  7 20:28 ..
-rw-r--r--. 1 root root 1319 Jul  7 20:29 query_export.py
# python ./query_export.py --redash-url "http://r1.redash.io" --api-key "api_key_here"
# ls -al
total 48
drwxr-xr-x. 2 root root  220 Jul  7 20:29 .
dr-xr-x---. 8 root root 4096 Jul  7 20:28 ..
-rw-r--r--. 1 root root  164 Jul  7 20:29 query_10.sql
-rw-r--r--. 1 root root  326 Jul  7 20:29 query_1.sql
-rw-r--r--. 1 root root  353 Jul  7 20:29 query_2.sql
-rw-r--r--. 1 root root  262 Jul  7 20:29 query_3.sql
-rw-r--r--. 1 root root  363 Jul  7 20:29 query_4.sql
-rw-r--r--. 1 root root  188 Jul  7 20:29 query_5.sql
-rw-r--r--. 1 root root  325 Jul  7 20:29 query_6.sql
-rw-r--r--. 1 root root  208 Jul  7 20:29 query_7.sql
-rw-r--r--. 1 root root  124 Jul  7 20:29 query_8.sql
-rw-r--r--. 1 root root  102 Jul  7 20:29 query_9.sql
-rw-r--r--. 1 root root 1319 Jul  7 20:29 query_export.py

[Note that r1.redash.io isn’t a real DNS name, it’s just a hard coded entry in my local /etc/hosts file, with the IP address of my Redash VM.]

As a first step, maybe try that, and see if that works for you? :smile:

If so, then with this list of the API end points, you may be able to update the Python script to grab the pieces you’re after:

The existing query_export.py script is using the /api/queries one on line 114 of that list.

Does that sound workable? :smile:

I copied the URL here.
python query_export.py --redash-url “URL in picture” --api-key “My api key just as in picture”

1 Like

Thanks for your replies.
Oh okies, I’m new to API so I’m still figuring out how to update the script to grab my queries.

Traceback (most recent call last):
  File "query_export.py", line 49, in <module>
    main()
  File "/Users/nicholas/Library/Python/2.7/lib/python/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/nicholas/Library/Python/2.7/lib/python/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/nicholas/Library/Python/2.7/lib/python/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/nicholas/Library/Python/2.7/lib/python/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "query_export.py", line 44, in main
    queries = get_queries(redash_url, api_key)      
  File "query_export.py", line 21, in get_queries
    queries.extend(response['results'])
KeyError: 'results'

I’ve managed to get a clearer error message. I took the exact same file as query_export.py.

Sounds like progress is being made, though it’s going a bit slowly. :wink:

One thing springs to mind… what the version of Redash running on the server you’re querying?

Asking because the list of API end points I gave above was correct for the current development version at the time of writing it. Didn’t think of that at the time. :innocent:

If you can find out the version of Redash on the running server, it shouldn’t be hard to get the correct list for that version. It will probably just be an earlier point in time for the same api.py file.

Thank you so much for your help. I researched and learnt enough to be able to export all my queries in SQL files. Hurray! I used the same python script provided by Redash.
To go deeper into exporting, how do I export only the queries from my favourite list or just selected queries. Eg query #48.

I tried editing the path in the script to…

    path = "{}/api/queries/favourites".format(url)

and

    path = "{}/api/queries/48".format(url)

but still, all queries are exported. May I trouble you to enlighten me if I’m on the correct path? Thanks a bunch

I’m not sure yet. :wink:

Looking into the API in good depth is on my near term ToDo list, but it’s behind a few other things which need doing first. Will probably have time to investigate later on today, or maybe tomorrow. Will keep this in mind when doing so though.

Oh, did you find out the version of Redash that’s running on your target server? Would be useful, so I can check if things have changed from that version to the current one, while I’m at it. :smile:

I believe I am using Version 7.0.0. So far, the one that worked for me is the url without < slug >

python ./query_export.py --redash-url "http:/{company_name}/no_slug" --api-key "api_key_here"

Slug will cause me the same error. Currently still trying to select just favourites queries or by query number.