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

Creating a new row in a table with Latenode

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

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

First, let's make sure to get the token according to the instructions in our article, only 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=[Replace the square brackets with the content of your token]'
  --data 'tableName=LatenodeTestSheet4Add'
  --data 'id=3'
  --data 'name=Latenode'

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

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}}"];
const newID = data["{{1.body.id}}"];
const newName = data["{{1.body.name}}"];

return {
	apiDriveURI,
	apiSheetURI,
	bToken,
	tableFileName,
	newID,
	newName
}

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/, after that substitute the value we got in the previous node {{ 3.body.files[ 0 ].id}}, and at the end /values/A:B:append?valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS&includeValuesInResponse=true;

メソッドを "Post "メソッドに変更する;

In the body of "raw" let's substitute:


{
	"range": "A:B",
	"majorDimension": "ROWS",
	"values": [[{{2.newID}}, "{{2.newName}}"]]
}

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

Let's also add a "Content-Type" header with the value "application/json";

保存」をクリックする;

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

Check our table, there should be a new entry;

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

See you in new articles

役立つリンク

Basic:

Latenode
Google OAuth 2.0 プレイグラウンド

情報

Google Drive API
Google Drive Files: list
Google Sheet API

Google Sheet Method: spreadsheets.values.append

関連ブログ

使用例

後援