Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets API v4: batchGet not working

Can't get Google Sheets API v4 to return multiple range values using batchGet. It is giving the following error (although the documentation says it needs valueRanges[], all the ranges and spreadsheetId are correct): "Extra args block must be a javascript object literal. (line 2, file "Code")"

Could you please help sort it out? Thank you. Here is the code:

function readRange(spreadsheetId) {
  var response = Sheets.Spreadsheets.Values.batchGet("someSpreadSheetID", ["Sheet1!D7:F7", "Sheet1!J7:L7"]);
  Logger.log(response.values);
}
like image 514
Din Avatar asked Aug 28 '17 14:08

Din


People also ask

Is Google Sheet API free?

All use of the Google Sheets API is available at no additional cost.


1 Answers

How about this modified script? In order to use this, please enable Sheet API v4 on API console and enable Sheet API v4 at Advanced Google Services.

Modified script :

function readRange(spreadsheetId) {
  var response = Sheets.Spreadsheets.Values.batchGet(
    "someSpreadSheetID",
    {ranges: ["Sheet1!D7:F7", "Sheet1!J7:L7"]}
  );
  Logger.log(response.valueRanges);
}
like image 189
Tanaike Avatar answered Oct 04 '22 00:10

Tanaike