1. はじめに
データ分析基盤をマーケター向けに作成しており、可視化ツールとしてredashを採用しています。redashは非エンジニアの方でもsqlが書ければ、手軽にデータをプロットできるので使い勝手が良いです。しかしながら、特定の機能についてはAPIを叩く必要があります。タイトルの通り、DashboardのコピーについてはGUIからはできませんが、APIを叩いて複製する方法があったので共有します。
2. 環境・前提
①コピーしたいダッシュボードのurlを確認
ex) https://redash.example.com/dashboard/example_test_board
②python実行環境 (python > 3.x)
3. 準備
- redash_host(urlのホスト部分)
- Slug(urlの最後の部分)
- example_test_board
- User API key
- Redashログイン>右上のアイコンクリック>Edit Profile>API Key を確認
- Redashログイン>右上のアイコンクリック>Edit Profile>API Key を確認
- 複製クエリ名を考える(元のクエリ名の頭に付与される)
- copy_smoto_
4. 方法
① redash-toolbeltをクローンする(※redash製のAPI簡易ラッパーです)
② クローンしたコード example/clone_dashboard_and_queries.py を実行
python clone_dashboard_andqueries.py {redash_host} {slug} {コピー名}
ex) python clone_dashboard_and_queries.py https://redash.example.com/ example_test_board copy_smoto_
③ API Key を問われるので、確認した API Key を入力
[xxx/redash-toolbelt/redash_toolbelt/examples] % python clone_dashboard_and_queries.py https://redash.example.com/ example_test_board copy_smoto_
API Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
④ コピー結果の確認(redash)
ダッシュボード名: Copy of: example_test_board
クエリ: copy_smoto_xxxx
5. 備考
- ダッシュボードを複製すると、クエリも全てコピーされます(テストでクエリがたくさんあるボードをコピーすると、削除するのが大変です)
- User API Key の取り扱いには注意してください (以下引用)
All the API calls support authentication with an API key. Redash has two types of API keys:
User API Key: has the same permissions as the user who owns it. Can be found on a user profile page.
Query API Key: has access only to the query and its results. Can be found on the query page.
Whenever possible we recommend using a Query API key.