Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda