# Use API to Get All Rows from Glide Table to Google Sheet

**URL:** https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659
**Category:** Ask for Help
**Created:** [November 22, 2022, 1:43am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659 "2022-11-22T01:43:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Clifton\_Crouch](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/clifton_crouch/32/24428_2.png) [@Clifton\_Crouch](https://community.glideapps.com/u/Clifton_Crouch)
#### Post date: [November 22, 2022, 1:43am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/1 "2022-11-22T01:43:04Z")

</div>

Hey, I’m new to working with APIs and trying to read through documentation and go through tutorials. I’d like to make sure what I’m trying to do is technically possible.

I have a Glide Table that is storing images. I would like to pull the data from the Glide Table into a Google Sheet so that I can use the Image Key from the Glide Table as validation criteria for the sheets that have columns to reference the images.

Is it possible to use Google Apps Script to use the “Get All Rows” API Instructions provided by Glide when you right click on the Table to do this?

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 22, 2022, 1:46am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/2 "2022-11-22T01:46:17Z")

</div>

> [@Clifton\_Crouch](#):
>
> Is it possible to use Google Apps Script to use the “Get All Rows” API Instructions provided by Glide when you right click on the Table to do this?

Yes, you can manipulate data in Glide Tables via the API using Apps Script.  
It’s not as simple as copy/paste though, if that’s what you are asking. You actually need to write a bit of code 😉

---

<div class="post-metadata">

### Author: ![Clifton\_Crouch](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/clifton_crouch/32/24428_2.png) [@Clifton\_Crouch](https://community.glideapps.com/u/Clifton_Crouch)
#### Post date: [November 22, 2022, 1:49am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/3 "2022-11-22T01:49:03Z")

</div>

Yes, I figured out that copy/paste doesn’t work haha. But I just wanted to make sure that my scenario was possible before I spent a lot of time trying to figure out how to get it working. I have a very basic understanding of JavaScript, so I need to spend some time working on it. Thanks!

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 22, 2022, 1:51am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/4 "2022-11-22T01:51:38Z")

</div>

Here is a bit of generic code that should get you started…

```auto
function get_all_rows(table) {
  var url = GLIDE_API_URL + 'queryTables';
  var obj = {
    appID: APP_ID,
    queries: [
      {
        tableName: table
      }
    ]
  }
  var payload = JSON.stringify(obj);
  var options = {
    method: 'POST',
    headers: {
      "Authorization": GLIDE_API_KEY,
      "Content-Type": "application/json"
    },
    payload: payload,
    muteHttpExceptions: true
  };
  var response = UrlFetchApp.fetch(url, options);
  var json = response.getContentText();
  var data = JSON.parse(json);
  return data;
}

```

---

<div class="post-metadata">

### Author: ![Clifton\_Crouch](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/clifton_crouch/32/24428_2.png) [@Clifton\_Crouch](https://community.glideapps.com/u/Clifton_Crouch)
#### Post date: [November 22, 2022, 4:04am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/5 "2022-11-22T04:04:28Z")

</div>

Thanks for the head start. I believe I have the API call working correctly now.

Now I’m trying to pass that data into the Google Sheet. I tried following a YouTube tutorial, but it didn’t quite match up.

I believe this part is working correctly and it gives me a menu option to run the Script:

```auto
function onOpen() {
  let ui = SpreadsheetApp.getUi();
  ui.createMenu('Glide')
    .addItem('Display Glide' , 'get_all_rows')  
    .addToUi();
}

```

However, I’m having trouble with the last part. So far I have this:

```auto
let sheet = SpreadsheetApp.getActiveSheet();

let glideRows = [];
glideRows.push(data.name);

let glide = [];
glide.push(glideRows);

let targetRange = sheet.getRange('A2:G');

targetRange.SetValues(glide);

```

I don’t know if I need to individually reference each column value using .push to insert each one, or if it can be something more generic to simply return everything.

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 22, 2022, 4:17am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/6 "2022-11-22T04:17:17Z")

</div>

> [@Clifton\_Crouch](#):
>
> ```auto
> let targetRange = sheet.getRange('A2:G');
> 
> targetRange.SetValues(glide);
> 
> ```

That’s probably going to fail because there will be a mis-match between the record count and the number of rows/columns in the range.

Also, it looks like you’re selecting a single attribute from the API result, but selecting 7 columns (A:G) in your spreadsheet. That won’t work.

And as far as I can see, you’re only pushing the first record. I would expect you’d need to iterate through the dataset and push all records.

What you need to do is count the number of records returned from the API, and select a range that corresponds to that. So maybe something like:

```auto
var num_rows = data.length;

```

and then later on…

```auto
sheet.getRange(2, 1, num_nows, num_cols).setValues(data);

```

---

<div class="post-metadata">

### Author: ![Clifton\_Crouch](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/clifton_crouch/32/24428_2.png) [@Clifton\_Crouch](https://community.glideapps.com/u/Clifton_Crouch)
#### Post date: [November 22, 2022, 5:29am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/7 "2022-11-22T05:29:43Z")

</div>

> [@Darren\_Murphy](#):
>
> Also, it looks like you’re selecting a single attribute from the API result, but selecting 7 columns (A:G) in your spreadsheet. That won’t work.

I had only typed out one because I couldn’t figure out the correct naming scheme.

I suppose I don’t actually need the data from all 7 columns, I just didn’t know if I had to pass all of it along. I really only need the data from the first column. The column name is “Name”, but I didn’t know how to properly reference that.

> [@Darren\_Murphy](#):
>
> What you need to do is count the number of records returned from the API, and select a range that corresponds to that. So maybe something like:

Is it okay to do something like A2:A since I don’t know the exact number of rows, but I’ll always want all of them?

I’ll play around with it some more, but I’ll probably just need to get my friend that knows JavaScript well to help.

Do you know of any good tutorials on the basics of integrating Apps Script with Google Sheets?

I’d like to learn it more in depth eventually, but I don’t have time to learn JavaScript from the ground up at the moment.

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 22, 2022, 5:38am UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/8 "2022-11-22T05:38:38Z")

</div>

> [@Clifton\_Crouch](#):
>
> Is it okay to do something like A2:A since I don’t know the exact number of rows, but I’ll always want all of them?

No, that won’t work. You need to select two-dimensional array (range) that is an _exact_ match for your data. But you can determine that by using `data.length`.

> [@Clifton\_Crouch](#):
>
> Do you know of any good tutorials on the basics of integrating Apps Script with Google Sheets?

There probably are, but I none that I can recommend.  
Personally, I just taught myself by referring to the [docs](https://developers.google.com/apps-script/reference/spreadsheet/).

---

<div class="post-metadata">

### Author: ![Clifton\_Crouch](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/clifton_crouch/32/24428_2.png) [@Clifton\_Crouch](https://community.glideapps.com/u/Clifton_Crouch)
#### Post date: [November 22, 2022, 6:37pm UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/9 "2022-11-22T18:37:54Z")

</div>

I got it all working now with some additional help from a friend. Thanks for your help!

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)
#### Post date: [November 23, 2022, 6:37pm UTC](https://community.glideapps.com/t/use-api-to-get-all-rows-from-glide-table-to-google-sheet/54659/10 "2022-11-23T18:37:55Z")

</div>

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