Glide Big Tables Advanced API Usage

Ask for Help Regulars

Hello all, I wanted to learn a how to write the code block to use the ‘get rows’ api for** big tables**, specifically, for tables crossing 10k rows. Apparently the API requires a continuation clause that allows the code block to check if there is more to offer than the first batch of 10k rows, if so, then the code block should continue to read the batch of the next 10k rows and so on.

Also, if any of the experts could show how to use the Big Tables API with filtered queries using the sql like query language, that would be immensely helpful.

Here is the link to glide’s documentation : Using Glide Tables API

Also, a side question would using the get rows api or the filtered query api for the big tables, be counted as an update?

Any script editor would do for the demo, even apps script!

Really hoping someone can help me out!

@Darren_Murphy

@Robert_Petitto

@Jeff_Hager

@ThinhDinh

@Sean_Martin

I’m not entirely sure about this, I believe it does cost 1 update but @Darren_Murphy might know better.

For cases where I do a query, I have always used the SQL query ever since Darren told me about it. I think the docs covered that pretty well, can you tell us where you got stuck?

I don’t know how to use the API at all yet. My best attempt was to make Google Bard create a code block for me in apps script but that did not really work :frowning:

I want to learn how to do these two things:

Being a “no - coder” I really do not know my way around API’s unless they are from make or Glide…

If you’re familiar with Make, the way to do it is to use the “HTTP” module.

https://www.make.com/en/help/tools/http

Please find the documentation there, play around with the module and let us know how it goes for you. I assume you have access to the Glide API already.

1 Like

Hello, I’ve been able to get this far using my code block in Google Apps Script and a little help from Chat GPT:

function Read_Rows_For_Any_Glide_Table(app_id, table_name) {
  console.log('Running ' + arguments.callee.name);

  var url = 'https://api.glideapp.io/api/function/queryTables';

  var headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer 006e44ef-39d3-4bb2-a************',
  };

  var rows = [];
  var nextToken = null;

  do {
    var payload = {
      appID: app_id,
      queries: [
        {
          tableName: table_name,
          startAt: nextToken,
        },
      ],
    };

    var options = {
      method: 'post',
      headers: headers,
      payload: JSON.stringify(payload),
      muteHttpExceptions: false, // Add this option to prevent exception
    };

    console.log('Running the API call using "URL Fetch"');
    var response = UrlFetchApp.fetch(url, options);

    if (response.getResponseCode() === 200) {
      var data = JSON.parse(response.getContentText());
      rows = rows.concat(data[0].rows);
      nextToken = data[0].next;
    } else {
      console.log('API request failed with response code: ' + response.getResponseCode());
      console.log('Full response content: ' + response.getContentText());
      break;
    }
  } while (nextToken);

  return rows;
}

function Test_Function_1() {

  var read_1 = Read_Rows_For_Any_Glide_Table('zvDeo8I******', 'native-table-ba0e1**********b382-72cdb7cb7239');

  console.log(read_1);
}

and yet I keep receiving this error: `1:29:30 PM	Error	
Exception: Request failed for https://api.glideapp.io returned code 400. Truncated server response: Bad Request (use muteHttpExceptions option to examine full response)
Read_Rows_For_Any_Glide_Table	@ Code.gs:33
Test_Function_1	@ Code.gs:51`.

I cannot move past this because Chat GPT is now just looping through once single answer which is incorrect.

Is there a reason you don’t use Make for this?

1 Like

Hey @ThinhDinh , I’ve made a short video explaining my situation to you, here

@ThinhDinh @Darren_Murphy @Sean_Martin @DarrenHumphries @Robert_Petitto

Any help is really appreciated.

Here is my code block that i am currently using in Apps Script:

//This function will read and return rows from any Glide Table part of the team: Ãlaap's Projects

/**
 * Reads and return rows from any Glide Table part of the team: Ãlaap's Projects
 * @param {String} app_id The ID of the app housing the Glide Table
 * @param {String} table_name The ID of the target table
 * @param {Object} continuation The "continuation JSON provided by the API if there are more rows to be read"
 * @return {Array} The API calls response
 */

function Read_Rows_For_Any_Glide_Table(app_id, table_name,continuation){

  //Commencing the function

  console.log('Running ' + arguments.callee.name);

  //Defining the API endpoint URL

  var url = 'https://api.glideapp.io/api/function/queryTables';

  //Defining the headers for authorizing the API call at Glide's serves

  var headers = 
  
    {
      'Content-Type': 'application/json',

      'Authorization': 'Bearer 0**********************462345',

    };

    //Defining the API's payload without a continuation that will help Glide's server identify where to read the data to return

    var payload_without_continuation =
    
      {

        appID: app_id,

        queries:
        
          [
            {
              tableName: table_name,
            },
          ],
      };

    //Defining the API's payload with a continuation that will help Glide's server identify where to read the data to return

    var payload_with_continuation =
    
      {

        appID: app_id,

        queries:
        
          [
            {
              tableName: table_name,

              startAt: continuation,
            },
          ],
      };

      //Using an if statement to determine which payload type to use by checking the length of the value of the 'continuation' paramter's key

      if(continuation || ''.length>0)

        {
          var usable_payload_1 = payload_with_continuation;

          console.log('Continuation data provided, attempting to call the next batch of data');
        }

      else

        {
          var usable_payload_1 = payload_without_continuation;

          console.log('Contination data not provided, attempting to call the first batch of data');
        }

    var options =
    
      {
        method: 'post',

        headers: headers,

        payload: JSON.stringify(usable_payload_1),

        muteHttpExceptions: false, // Add this option to prevent exception
      };

    console.log('Running the API call using "URL Fetch"');

    var response = UrlFetchApp.fetch(url, options);

    var data = JSON.parse(response.getContentText());

    console.log('Terminated ' + arguments.callee.name);

    return data;

  //Terminating function
      
}

//This is a test function used to call back another function that will help read rows from a glide table

function Test_1(){

  var json_response_1 = Read_Rows_For_Any_Glide_Table('zvDeo8IUE7L51X3piXh8','native-table-ba0e1a5f-b661-4408-b382-72cdb7cb7239');

  console.log({'api_response_1':json_response_1});

  var next_reponse = json_response_1[0]['next'];

  if(next_reponse.length>0)

    {
      var next_reponse_parsed = JSON.parse(next_reponse);

      var json_reponse_2 = Read_Rows_For_Any_Glide_Table('zvDeo8IUE***','native-table-ba0e*******************239',next_reponse_parsed);

      console.log({'api_response_2':json_reponse_2});
    }

  else

    {

    }

}```