開発ツール
アントニー・ショー
マーケティングの専門家
2022年12月29日
ノーコードのシンプルさとフルコードのパワーを融合したローコード・プラットフォーム 🚀。
無料で始める
2022年12月29日
-
5min
min read

Reading API data from Google table with Latenode

アントニー・ショー
マーケティングの専門家
目次

注:プロジェクトのLatenode チェーンに新しいノードを追加した後、前のノードのデータにアクセスするには、プロジェクトを実行し、必要なすべてのデータを含むチェーンを呼び出す必要があります。JavaScript "ノードから "HTTPリクエスト "ノードに代入されるデータは、しばしば二重引用符でエスケープする必要があります。リモートサーバーからのリクエストに応答して受信した複雑なオブジェクトや配列は、文字列として送られてくるため、"JavaScript "ノードで対応するデータ型と同じように扱うには、JSON.parseで処理する必要があります。

First of all let's get the token according to the instructions in our article, but in the list choose "Google Sheets API v..." scope "www.googleapis.com/auth/spreadsheets" and "www.googleapis.com/auth/drive";

Create a new table, you can for example call it "LatenodeTestSheet4Add", with two columns "ID" and "Name";

一休のクライアントにリクエストを用意してみよう;

REQ01: レストクライアントのリクエスト


    curl --request POST  --url 'https://webhook.latenode.com/69/dev/becaa2c2-fcf6-4ef8-89a9-f375b3c0ba26?='
    --header 'Content-Type: application/x-www-form-urlencoded'
    --data 'token=[change everything inside the square brackets along with them]'
    --data 'tableName=LatenodeTestSheet4Add'

冒頭のステップで得たトークンを代入してみよう;

Webhook」ノードを作成します:「ノードの追加" => "Http" => "Webhook";

Webhookのアドレスをコピーし、残りのクライアントのアドレスバーに貼り付けます;

Next, add another "JavaScript" node: "+ Add Node" => "Code" => "JavaScript";

セーブする;

ノードを結びつける;

ノード間でデータを転送するために、チェーンを開始し、呼び出そう;

その中に内容をコピーしてみよう:


    const apiDriveURI = "https://www.googleapis.com/drive/v3/files";
    const apiSheetURI= "https://sheets.googleapis.com/v4";
    const bToken = "Bearer " + data["{{1.body.token}}"];
    const tableFileName = data["{{1.body.tableName}}"];
    
    return {
    							apiDriveURI,
                  apiSheetURI,
                  bToken,
                  tableFileName,
                }

Let's check in all constructions like "data["{{1.body.name}}"]" that the number of Webhook corresponds to the one we are getting data from, if not replace it with the necessary one (let me remind you that 1 is the node number written just below the node name above the node type, then if it is a query then the object field responsible for the type of sent/received data is selected - body for forms or query for query parameters);

変更を保存する;

Create the "HTTP request" node to get the id of the table file: "+ Add node" => "Http" => "HTTP request";

セーブする;

ノードを結びつける;

ノード間でデータを転送するために、チェーンを開始し、呼び出そう;

Let's form the "Url" field: at the beginning let's substitute the variable "apiDriveURI" from "JavaScript", after it we specify ?:q=name "variable tableFileName from "JavaScript"";

デフォルトのメソッドが "Get "であることを確認してください;

Let's add the "Autorization" header and the "bToken" variable from "JavaScript" to its value;

保存」をクリックする;

Create the "HTTP request" node to add data: "+ Add node" => "Http" => "HTTP request";

セーブする;

ノードを結びつける;

ノード間でデータを転送するために、チェーンを開始し、呼び出そう;

Let's form the "Url" field: at the beginning let's substitute the variable "apiSheetURI" from "JavaScript", after it /spreadsheets/, then let's substitute the value we got in the previous node {{ 3.body.files[ 0 ].id}}, and then /values/A:B;

デフォルトのメソッドが "Get "であることを確認してください;

Let's add the "Autorization" header and the "bToken" variable from the first "JavaScript" node to its value;

保存」をクリックする;

Let's create a "Webhook response" node to return found values: "+ Add node" => "Http" => "Webhook response";

セーブする;

ノードを結びつける;

ノード間でデータを転送するために、チェーンを開始し、呼び出そう;

Let's add in the return values from the previous query with the data from cells {{ 4.body.values.[ 0 ]}}

After calling the whole chain, the contents of the cells will be returned;

Latenode 、チェーン全体の最後には次のようになる:

See you in new articles;

役立つリンク

Basic:

Latenode

Google OAuth 2.0 Playground

情報

Google Drive API
Google Drive Files: list
Google Sheet API

Google Sheet Method: spreadsheets.values.get

関連ブログ

使用例

後援