![image](/wp-content/uploads/2021/10/enebular-airtable_01.png)
スプレッドシートのような操作感でデータを管理できる Airtable というサービスがあります。
node-red-contrib-airtable (node)
![image](/wp-content/uploads/2021/10/enebular-airtable_02.png)
APIも使いやすくデータの読み書きもしやすいうえ、Node-RED のノードもあって扱いやすいです。今回は enebular でのセットアップから簡単なデータの読み込みまでを説明します。
![image](/wp-content/uploads/2021/10/enebular-airtable_03.png)
Pricing – Airtable で 価格表を確認すると 2021/10 現在、
✓ 無制限の Base
✓ Base あたり1,200レコード
✓ Base あたり2GBの添付ファイル
✓ グリッド、カレンダー、かんばん、フォーム、およびギャラリービュー
が無料枠で含まれるので、とりあえず触ってみても基本的な機能を体験しやすいものになっています。
アカウント作成
![image](/wp-content/uploads/2021/10/enebular-airtable_04.png)
サインアップ からアカウント作成をすすめて準備をします。
データのかたまり Base を準備する
AirTable ではスプレッドシートのようなデータのかたまりを Base と呼びます。
英語ですが、こちらの記事 Creating a new empty base も参考になります。
![image](/wp-content/uploads/2021/10/enebular-airtable_05.png)
Add a base のボタンから Start from scratch から、シンプルなテーブルではじめます。
![image](/wp-content/uploads/2021/10/enebular-airtable_06.png)
Untitled Base ができます。
![image](/wp-content/uploads/2021/10/enebular-airtable_07.png)
Table 1 を見ます。Name ・ Notes ・ Attachments ・ Status という列ができています。
![image](/wp-content/uploads/2021/10/enebular-airtable_08.png)
Name にデータを入れておきます。 Test1 Test3 Test3 と入力しておきます。
アカウントページで API Key をメモする
![image](/wp-content/uploads/2021/10/enebular-airtable_09.png)
アカウントでログインした状態で アカウントページ に移動します。
![image](/wp-content/uploads/2021/10/enebular-airtable_10.png)
API のテキストフィールドをクリックすると API Key が表示されるのでメモしておきます。 Regenerate API key や Delete key をうっかりクリックしないように気をつけましょう。
今回作った Base の ID を取得する
![image](/wp-content/uploads/2021/10/enebular-airtable_11.png)
アカウントでログインした状態で REST API という各 Base の API 取得方法が見られるページに移動します。
![image](/wp-content/uploads/2021/10/enebular-airtable_12.png)
今回作った Base をクリックします。
![image](/wp-content/uploads/2021/10/enebular-airtable_13.png)
INTRODUCTION が表示されるので The ID of this base is のところの app ではじまる Base ID をメモしておきます。
これで準備は完了です。
Discover Flow
![image](/wp-content/uploads/2021/10/enebular-airtable_14.png)
今回の Discover Flow をインポートします。
![image](/wp-content/uploads/2021/10/enebular-airtable_15.png)
インポートの後、Edit ボタンをクリックして編集します。
![image](/wp-content/uploads/2021/10/enebular-airtable_16.png)
フローが表示されました。
フローの設定をする
![image](/wp-content/uploads/2021/10/enebular-airtable_17.png)
airtable ノードをダブルクリックしてプロパティを表示します。
![image](/wp-content/uploads/2021/10/enebular-airtable_18.png)
プロパティが表示されました。Set API Key が My API Key となっているので横の鉛筆マークをクリックします。テーブル名はすでに Table 1 で設定済みです。
![image](/wp-content/uploads/2021/10/enebular-airtable_19.png)
API Key と Base Id に入力していきます。
- API Key
- 先ほどメモした API Key
- Base Id
- 先ほどメモした Base の ID
を入力して更新をクリックします。
![image](/wp-content/uploads/2021/10/enebular-airtable_20.png)
完了をクリックします。
![image](/wp-content/uploads/2021/10/enebular-airtable_21.png)
デプロイをクリックして今回の動作を反映します。
動かしてみる
![image](/wp-content/uploads/2021/10/enebular-airtable_22.png)
デプロイしてたら動かしてみましょう。
![image](/wp-content/uploads/2021/10/enebular-airtable_23.png)
inject ノードをクリックします。
![image](/wp-content/uploads/2021/10/enebular-airtable_24.png)
クリックするとデバッグタブに値が3つ表示されます。
![image](/wp-content/uploads/2021/10/enebular-airtable_25.png)
無事、仮で入力した Test1 Test3 Test3 が表示されました。
このように、AirTable と Node-RED でデータが簡単に取得することができました。この手法だけでも、AirTable に Google スプレッドシートと同じようにデータを入力して直感的な GUI で管理できますし、 Node-RED 側でさらにダッシュボードに表示したり、他の API と掛け合わせて分析してみたりできますね!
その他にも、データを Node-RED 側から書き込んだり より細かく検索できたりと、さまざまなことが可能になるので今後ご紹介します。