Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Preventing GoogleJsonResponseException: API call to sheets.spreadsheets.batchUpdate failed with error: Must specify at least one request

I have the following Google Spreadsheet function:

function deleteRows() {
  const sheetName = "Sheet"; // Please set the sheet name.
  
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName(sheetName);
  const sheetId = sheet.getSheetId();
  const requests = sheet
    .getRange(`S1:S${sheet.getLastRow()}`)
    .createTextFinder("Found")
    .findAll()
    .map(r => r.getRow())
    .reverse()
    .map(r => ({deleteDimension:{range:{sheetId:sheetId,startIndex:r - 1,endIndex:r,dimension:"ROWS"}}}));
  Sheets.Spreadsheets.batchUpdate({requests: requests}, ss.getId());
}

The script deletes duplicated rows with API's batchUpdate, if there is text "Found" within column S, however sometimes there are no duplicated rows, hence I would like the function not to return the error:

GoogleJsonResponseException: API call to sheets.spreadsheets.batchUpdate failed with error: Must specify at least one request.

and just go on with the next function which runs after finishing the above deleteRows function.

How to prevent returning the error if there is no request?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your situation, how about the following modification?

From:

Sheets.Spreadsheets.batchUpdate({requests: requests}, ss.getId());

To:

if (requests.length > 0) {
  Sheets.Spreadsheets.batchUpdate({requests: requests}, ss.getId());
}
  • By this modification, when requests has the values, Sheets.Spreadsheets.batchUpdate is run.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!