Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda