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>
  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
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)


    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.

I managed to import all queries (still unable to select by fav/ by number) but I am still stuck at importing queries into another Redash account.

Anyone have any idea how to import? I used the script in the comments from export but didn’t work.

Sorry for the delay, and no firm answer yet either. :frowning:

Started putting together initial pieces for an API doc (manually), with the idea of creating working examples for each function. Obviously, there is a long, long way to go as nearly everything atm is “To Do”:

So far, it looks like most of the API calls there are “read only”. eg useful for querying data.

I still need to figure out how to create things (eg new data source) with the API. That would probably be useful for you too. eg import queries from API on server one, then create selected queries from that on server too.

Thank you for your reply. Oh that’s great! It would help future users.

Some progress along the way, I found out I am able to import queries back to my own account.

Account A -> Export Query -> Local Desktop(Passed)
Local Desktop(made changes to SQL files) -> Import Query -> Account A (Passed with 200)

Account A -> Export Query -> Local Desktop(Passed)
Local Desktop(made changes to SQL files) -> Import Query -> Account B(Failed with 404)

I am testing with 70 queries and the new account has 0 queries created.

Is it because it is only possible to import back to the same account you exported from?
Is it possible to import to a whole new account?

After all, all these are on a query level. I am still looking to export, import on a larger scale. (Eg. Visualisations and dashboards)

On the new account, does querying it (or other API calls) work?

eg Is the slug and URL for account B 100% correct? :smile:

Yup. I made a new query on the new account. I am able to export and import.

How I get my API key: Edit Profile → Account → API Key
I also get the URL from this page. And just remove {users/me}