Updating single cells in batch using googlespreadsheet api v4?

  google-sheets, google-sheets-api, php
$range1 = new Google_Service_Sheets_GridRange();
$range1->setStartRowIndex(1);
$range1->setEndRowIndex(1);
$range1->setStartColumnIndex(92);
$range1->setEndColumnIndex(92);

$range2 = new Google_Service_Sheets_GridRange();
$range2->setStartRowIndex(5);
$range2->setEndRowIndex(5);
$range2->setStartColumnIndex(92);
$range2->setEndColumnIndex(92);

$request1 = new Google_Service_Sheets_UpdateCellsRequest();
$request1->setFields('BATCHUPDATE');
$request1->setRange($range1);
$body1 = new Google_Service_Sheets_Request();
$body1->setUpdateCells($request1);



$request2 = new Google_Service_Sheets_UpdateCellsRequest();
$request2->setFields('BATCHUPDATE2');
$request2->setRange($range2);
$body2 = new Google_Service_Sheets_Request();
$body2->setUpdateCells($request2);

$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$batchUpdateRequest->setRequests([$body1, $body2]);

The documentation is confusing, because I tried to do several ways, but it didn’t work and this way doesn’t work either.

https://developers.google.cn/sheets/api/reference/rest/v4/spreadsheets/request?hl=zh-cn#UpdateCellsRequest

There’s no other request for updating a single cell, and the way I did it doesn’t seem to work.

Fatal error: Uncaught GoogleServiceException: {
  "error": {
    "code": 500,
    "message": "Internal error encountered.",
    "errors": [
      {
        "message": "Internal error encountered.",
        "domain": "global",
        "reason": "backendError"
      }
    ],
    "status": "INTERNAL"
  }
}

Do I really have to make several calls instead of batching them? I am trying to update single cells in a batch instead of calling the update call several times.

Source: Ask PHP

LEAVE A COMMENT