2
batch_update_spreadsheet_request_body = {
    'requests': [
        {
            "updateCells": {
                "rows": [
                    {
                        "values": [
                            {
                                "userEnteredValue": {
                                    "boolValue": False
                                }
                            }
                        ]
                    }
                ],
                "fields": "userEnteredValue",
                "start": {
                    "sheetId": "target_sheet_id",
                    "rowIndex": 0,
                    "columnIndex": 0
                }
            },
            "updateSheetProperties": {
                    "properties": {
                        "sheetId": "target_sheet_id",
                        "title": "Some title"
                    },
                    "fields": "title"
            }
        }
    ]
}

request = service.spreadsheets().batchUpdate(
    spreadsheetId=spreadsheet_id,
    body=batch_update_spreadsheet_request_body)
request.execute()

This code results in following error: "Invalid value at 'requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'updateSheetProperties'". Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'requests[0]', 'description': "Invalid value at 'requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'updateSheetProperties'"}]}]"

But separately each request body is working:

batch_update_spreadsheet_request_body = {
    'requests': [
        {
            "updateCells": {
                "rows": [
                    {
                        "values": [
                            {
                                "userEnteredValue": {
                                    "boolValue": False
                                }
                            }
                        ]
                    }
                ],
                "fields": "userEnteredValue",
                "start": {
                    "sheetId": "target_sheet_id",
                    "rowIndex": 0,
                    "columnIndex": 0
                }
            }
        }
    ]
}

As well as "updateSheetProperties" request body. Reading documentation doesn't help, I've also tried to find answers elsewhere but to no avail.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • This is for slides but has similar error: https://stackoverflow.com/questions/53137069/error-invalid-value-at-requests0-oneof-oneof-field-kind-is-already-set – Zircoz Jun 23 '20 at 16:56

1 Answers1

2

How about this answer?

Modification point:

  • I think that the reason of your issue is that UpdateCellsRequest and UpdateSheetPropertiesRequest are included in one element in the array of the request. In this case, please separate them for each element in the request.

When this point is reflected to your script, it becomes as follows. In this modification, batch_update_spreadsheet_request_body is modified.

Modified script:

batch_update_spreadsheet_request_body = {
    'requests': [
        {
            "updateCells": {
                "rows": [
                    {
                        "values": [
                            {
                                "userEnteredValue": {
                                    "boolValue": False
                                }
                            }
                        ]
                    }
                ],
                "fields": "userEnteredValue",
                "start": {
                    "sheetId": "target_sheet_id",
                    "rowIndex": 0,
                    "columnIndex": 0
                }
            }
        },
        {
            "updateSheetProperties": {
                "properties": {
                    "sheetId": "target_sheet_id",
                    "title": "Some title"
                },
                "fields": "title"
            }
        }
    ]
}

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165