6
votes

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);
}
2

2 Answers

7
votes

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);
}
0
votes

I made this in-depth tutorial on how to easily access the Google Sheets API V4. Let me know what you think!

https://medium.com/@inaguirre/google-sheets-api-tutorial-with-javascript-588f581aa1d9

It is pretty simple if you know how to use fetch().