Import your Glide Table into any Google Sheet, with 1 formula!

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:

  1. Create a new Google Spreadsheet

  2. Click on ‘Extensions’ and then on Apps Script

  3. 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);
    }
}
  1. Press the save button on the top left

  2. Reload your spreadsheet

  3. Go to a new cell in the spreadsheet and input this formula:
    ‘=Return_Rows_From_Normal_Glide_Table()’

  4. You will have to feed this formula 3 things:

  • Your authorization token → (Bearer 83u2h8duxebuz9m1z)

  • Your app ID

  • Your table name

  1. 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”)

  1. 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 :man_mage:
api
Project Showcase

4 Likes

Sounds interesting.

1 Like

@Alaap_Kanchwala - I’ve taken the liberty of fixing the formatting of your code block. Also, you shared what appeared to be your Glide API key in this post. I’ve removed that.

4 Likes

@Darren_Murphy

Hey Darren, thank you so much!

I completely forgot about removing the API key!

Also, I don’t know how to make this work for a BIG Table that scales more than 10,000 rows, please do build on that if you can! :smile:

Yes, I know I promised you a tutorial. I’ll get to it eventually, but it’s not a good time for me at the moment.

1 Like

Of course, no worries, I look forward to it!

Thank you for helping out! :grin:

Are we capable of running rollups on this Google Sheet if not connected to our App and not get hit with Rows? Or should we have a separate google sheet that does the rollups and connect that to our app?

1 Like
  1. You will only be able to import the non-computed columns. So your roll up columns, math columns etc, will not be imported.

  2. If you want to perform those calculations in your google sheets, you can do so in columns that will not be in the way your glide data range.

For example, you can perform your rollups and other calculations from column ‘N’ if you know that you Glide tables only has 13 columns, so the google sheet will only populate data from column ‘A:M’.

I hope that answers your question :smile:

Very interesting but I still have a doubt:

if I retrieve 1500 rows from my GT to my GS, those 1500 rows will count as 1500 updates?

If not, it would be a wonderful tool to create a kind of historical data storage outside of any application.

Thanks!

1 Like

@Alaap_Kanchwala what is your use case for this ? Have you thought of other use cases ?

1 Like

Hey, of course not. This feature uses the get rows api that is completely free.

You could import your 1500 rows once a minute at no cost.

Hello @Krivo,

My current use case for this is to quickly generate PDF documents from my Google sheet using apps script.

If I want to create an invoice for a PDF, i am charged 5 updates per PDF.

In this case, I will be charged 1 updates where in the user can provide which invoice they need, then the Google sheet will run some apps script and email them the PDF within 30 seconds. Costing only one update per PDF.

1 Like

Thanks for your reply,

To be honest I haven’t fully tested the Glide API retrieving many rows at the same time. I am noticing in your code that it retrieves all GT data at once but now I wonder: does the API support some kind of “SQL clause” to filter the rows I want to put in my GS?

I mean, instead of retrieving my 1500 rows, only retrieving those with Date <=“2022/12/01” ??

Saludos!

1 Like

Yes, but only with Big Tables.

3 Likes

Thanks Darren!

2 Likes

Does it consume your quota when you do a query?

1 Like

I’m fairly certain that each Get Rows calls will cost one update.

1 Like

I’m not sure if a get rows call to a regular glide table consumes an update. A get rows call to a big table might, since they will have to query the data.

I have a project that reads about 1k rows from a glide tables every minute to sync to a Google sheet.

It’s been working for months and yet it does not cost me more than 100-200 updates per month. That too, the cost is justified by any adds, edits or deletes.

Okay, you might be right. I’ll see if I can get clarification on that.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.