user201817
user201817

Reputation: 11

Google Sheets error 400 "exceeds grid limits"

I am trying to get a JSON body for a sheet using Chrome for now, but to be incorporated in a python script.

https://sheets.googleapis.com/v4/spreadsheets/[spreadsheet_id]/values/[tab_name]?alt=json&key=[api_key]

The sheet contains 56 rows and 6 columns, but I get the error:

{
  "error": {
    "code": 400,
    "message": "Range ('tab_name'!TAB_NAME) exceeds grid limits. Max rows: 994, max columns: 26",
    "status": "INVALID_ARGUMENT"
  }
}

I was thinking it did not like the alt=json anymore, but I get the same error with just the key on the end.

Upvotes: 0

Views: 2580

Answers (2)

LeoRochael
LeoRochael

Reputation: 15187

Make sure to quote the tab name with single quotes

You mention accessing the API as:

https://sheets.googleapis.com/v4/spreadsheets/[spreadsheet_id]/values/[tab_name]?alt=json&key=[api_key]

I've been through the same issue recently, and if you're receiving an error like:

exceeds grid limits. Max rows: XXX, max columns: YYY

Then the problem might be with the way you're representing [tab_name].

A similar issue was reported in the pygsheets library. The fix was to quote the tab name with single quotes, as in:

https://sheets.googleapis.com/v4/spreadsheets/[spreadsheet_id]/values/'[tab_name]'?alt=json&key=[api_key]

The reason for that is that sometimes the tab name can be interpreted as a range. Something like APP1 could be seen by gsheets as trying to refer to the column APP, row 1, rather than the tab named APP1.

Adding single quotes around the tab name makes sure the google API interprets it as a tab name, rather than a cell address or range.

Upvotes: 0

Jose Vasquez
Jose Vasquez

Reputation: 1728

A proper range is not defined

I assume you are trying to get values from a Sheet, as per the documentation the proper way to use this endpoint is GET https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{range} you defined [tab_name] as part of the URL which is equal to SheetName or sheetName!A:Z, in other words, the error states that your request exceeds grid limits so you have to define a smaller grid, e.g. GET https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/Sheet1!A1:C5.

As a suggestion I encourage you to take a look at the examples in the documentation.

Upvotes: 0

Related Questions