Development tools

Reading API data from Google table with Latenode

Antony Show
Marketing Expert
August 10, 2023
A low-code platform blending no-code simplicity with full-code power
Get started free

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

Let's prepare a request for our rest client;

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=[change everything inside the square brackets along with them]'
    --data 'tableName=LatenodeTestSheet4Add'

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}}"];
    
    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);

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/, then let's substitute the value we got in the previous node {{ 3.body.files[ 0 ].id}}, and then /values/A:B;

Make sure that the default method is "Get";

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

Click "Save";

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

Save;

Tie the nodes together;

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

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;

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.get

Related Blogs