How to specify the gid (tabs) in Google Spreadsheet API v4?

Jamie Phan picture Jamie Phan · May 2, 2017 · Viewed 7.3k times · Source

I am trying to use RESTful API go gather the data from a Google spreadsheet spreadsheet.

I reviced the document at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get but I cannot find the key that allow me to specify a specific GID (tabs) of the spreadsheet.

After call the API, I was able to get a value from the first tab of the spreadsheet, but I want to change it to the second page (another GID)

Any help would be appreciated. Thanks.

Edit: Added example:

I have a sample spreadsheet here: https://docs.google.com/spreadsheets/d/1da3e6R08S8OoibbOgshyAQy7m9VRGPOrSGzVIvMSXf4/edit#gid=0

When I want to get the value on A1, I can call the RESTful API:

https://content-sheets.googleapis.com/v4/spreadsheets/1da3e6R08S8OoibbOgshyAQy7m9VRGPOrSGzVIvMSXf4/values/A1?key=API_KEY

And I will get:

{
  "range": "Sheet1!A1",
  "majorDimension": "ROWS",
  "values": [
    [
      "This is on the first tab!"
    ]
  ]
}

But as you see in my spreadsheet, I have to tabs (sheet2), how can I get that value of "This is on the second tab!"?

Answer

RAMESHKUMAR picture RAMESHKUMAR · Aug 3, 2017

To specify a specific GID (tabs) of the spreadsheet. Enter your 'sheet_name' with single quotes. Don't miss to add double quotes for range. Hope it helps

var query = {
        auth: authClient,
        spreadsheetId: 'spreadsheetID', 
        range: "'sheet1'!A1:D3",
    };