Skip to content
Advertisement

“Invalid requests[0].updateCells: Invalid field” when using barchUpdate on googlespreadsheet API

$range1 = new Google_Service_Sheets_GridRange();
$range1->setStartRowIndex(92);
$range1->setEndRowIndex(92);
$range1->setStartColumnIndex(4);
$range1->setEndColumnIndex(4);
$range1->setSheetId(1433074761);

$range2 = new Google_Service_Sheets_GridRange();
$range2->setStartRowIndex(92);
$range2->setEndRowIndex(92);
$range2->setStartColumnIndex(2);
$range2->setEndColumnIndex(2);
$range2->setSheetId(1433074761);

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



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

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

So I was able to fix an error I had, but now I am getting an error for the field entered through the setFields method. I thought you could put any string, but it seems that it’s not the case at all. The documentation doesn’t seem to provide what might be the issue.

I get the error:

Fatal error: Uncaught GoogleServiceException: {
  "error": {
    "code": 400,
    "message": "Invalid requests[0].updateCells: Invalid field: aaaaaaaaaaaaaaaa
aaaaaaaaaaaa",
    "errors": [
      {
        "message": "Invalid requests[0].updateCells: Invalid field: aaaaaaaaaaaa
aaaaaaaaaaaaaaaa",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

https://developers.google.com/resources/api-libraries/documentation/sheets/v4/php/latest/class-Google_Service_Sheets_GridRange.html

The documentation itself says that the parameter can be mixed, so can be anything, but it doesn’t seem to work.

https://php.watch/versions/8.0/mixed-type

Advertisement

Answer

Even though the type of the parameter is mixed. It doesn’t mean that the value could be anything. You need to check it in the reference document.

In UpdateCellsRequest,

fields – string ( FieldMask format)

The fields of CellData that should be updated. At least one field must be specified. The root is the CellData; ‘row.values.’ should not be specified. A single “*” can be used as short-hand for listing every field.

See available fields of CellData here.


My concern regarding your code is that, you are tying to use UpdateCellsRequest but you did not provide the rowData (data to write) to be used. You just provided a gridrange (range to write data).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement