This feature will allow you to go into your Google Sheet ad simply write this formula: ‘=Return_Rows_From_Normal_Glide_Table()’ and then magically, your Google sheet will sync with your Glide Table instantly and at no cost!
This Google Sheet is not required to be connected to your project
All you have to do is this:
-
Create a new Google Spreadsheet
-
Click on ‘Extensions’ and then on Apps Script
-
Paste this code in the Apps Script Editor:
//This function will allow a you to read any normal Glide Table that you have access to in your team
/**
* Reads and returns the rows from a normal Glide Table.
* @param {String} auth_bearer_token Your secret code given to your tema by Glide. Do not share at any cost!
* @param {String} app_id Your app ID will be shown in the 'Show API' section when you right click on your table in the editor.
* @param {String} table_name Your Glide table's native name as shown in the 'Show API' section when you right click on your table in the editor.
* @return {Array} Returns all the rows in your Glide table. Unfortunately, the headers cannot be replicated.
* @customfunction
*/
function Return_Rows_From_Normal_Glide_Table(auth_bearer_token,app_id,table_name){
//This line of code will act as a commencement log for this function in your console
console.log('Commencing '+arguments.callee.name);
//Trying to catch errors within the running of the function
try
{
//Defining the API endpoint URL
var url = 'https://api.glideapp.io/api/function/queryTables';
//Defining the headers of the API so that Glide's servers can verify our API call
var headers =
{
'Content-Type': 'application/json', //For any API call to Glide, the content type will be 'application/json'
'Authorization': auth_bearer_token // Your secret code given to your tema by Glide. Do not share at any cost!
};
//Defining part of the paylod of the API so that Glide can recognise which table we are targeting to read the rows from
var data =
{
//Defining the app ID
appID: app_id,
//Defining the core part of the payload that will help target the specific table
queries: [
{
tableName: table_name, //Your Glide table's native name as shown in the 'Show API' section when you right click on your table in the editor.
}
]
};
//Compressing the JSON objects into the 'options' variable we created above to help pass it into the API call that will match the format expected by Glide.
var options =
{
method: 'post', //The type of API call we are making. In glide, even a 'GET' call is made by a 'POST' request
headers: headers,
payload: JSON.stringify(data), //Stringifying the
muteHttpExceptions: true // Add this option to see any errors that may occur in during the API call
};
console.log('Calling the GET ROWS API');
var response = UrlFetchApp.fetch(url, options);
var response_parsed = JSON.parse(response.getContentText()); //Parsing the response to a JSON format for Google Sheets to read the data.
//Extrating thw rows data from the received JSON
var rows_data = response_parsed[0]['rows'];
console.log(rows_data.length >= 1);
if(rows_data.length >= 1)
{
console.log('1 or more rows were returned in the API call');
//Extracting all the JSON keys from the first row
var column_key_values = Object.keys(rows_data[0]);
//Defining a big empty array to populate with data
var big_empty_array = [];
//Looping through each of the returned rows to set as values in the sheet cells
var looper_1 = rows_data.forEach(row_json =>
{
//Defining what to do within eah loop
//Defining a small empty array
var small_empty_array = [];
var row_array = column_key_values.forEach(key =>
{
var value = row_json[key];
small_empty_array.push(value);
});
//Pushing the small array into the big array
big_empty_array.push(small_empty_array);
});
//Returning the big array to populate the google sheet cells
return big_empty_array;
}
else
{
console.log('No rows were returned in the API call');
throw Error('There was no data returned in the response');
}
}
catch(error)
{
throw Error(error);
}
}
-
Press the save button on the top left
-
Reload your spreadsheet
-
Go to a new cell in the spreadsheet and input this formula:
‘=Return_Rows_From_Normal_Glide_Table()’ -
You will have to feed this formula 3 things:
-
Your authorization token → (Bearer 83u2h8duxebuz9m1z)
-
Your app ID
-
Your table name
- Ensure that all of these three parameters and individually wrapped in “quotations”.
-
This is how the function will look if written perfectly:
-
=Return_Rows_From_Normal_Glide_Table(“Bearer XXXXX”,“zvDeo8IUE7jrc1X3piXh8”,“native-table-f438jKm1Jm6DHIVMPOcR5”)
- Once you write the formula perfectly, you Glide Tables data will be populated into spreadsheet, instantly.
The data from the Glide table will sync upon refresh of the spreadsheet
#GoogleAppsScript
#GoogleSpreadsheets
#GoogleSheets
#GlideTablesSync
Spreadsheet Magic
api
Project Showcase