Development tools

Creating a new row in a table with Latenode

Antony Show
Marketing Expert
December 29, 2022
A low-code platform blending no-code simplicity with full-code power
Get started free
Table of contents

Say no to chaotic work. Automate your tasks now.

Note: After adding new nodes in the Latenode chain of a project, to access the data from the previous nodes, you need to run the project and call the chain with all the necessary data. Data substituted from "JavaScript" node into "HTTP request" node often needs to be escaped with double quotes. Complex objects or arrays received in response to request from remote servers and coming as string must be processed by JSON.parse in order to work with them in "JavaScript" nodes as with corresponding data type.

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: Request for rest client


  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'

Let's substitute our token obtained from the step at the beginning;

Create a "Webhook" node: "+ Add node" => "Http" => "Webhook";

Copy the Webhook address and paste it into the rest client address bar;

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

Save;

Tie the nodes together;

Let's start and call the chain to transfer data between the nodes;

Let's copy the contents into it:


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

Save the changes;

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

Save;

Tie the nodes together;

Let's start and call the chain to transfer data between the nodes;

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"";

Make sure that the default method is "Get";

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

Click "Save";

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

Save;

Tie the nodes together;

Let's start and call the chain to transfer data between the nodes;

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;

Change the method to the "Post" method;

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";

Click "Save";

Let's start and call the chain to transfer data between the nodes;

Check our table, there should be a new entry;

At the end of the whole chain in Latenode will look like this:

See you in new articles

Useful links:

Basic:

Latenode
Google OAuth 2.0 Playground

Information:

Google Drive API
Google Drive Files: list
Google Sheet API

Google Sheet Method: spreadsheets.values.append

Related Blogs

Backed by