Search code examples
google-slides-api

Google Slides API reports Invalid requests[0].updateTableCellProperties: Invalid field: table_cell_properties


Trying to troubleshoot an error message my app gets after sending a batchUpdate request to Google Slides API

Invalid requests[19].updateTableCellProperties: Invalid field: table_cell_properties 

The 19th request in the batch is the only updateTableCellProperties request I have. If I removing the 19th request from the batch, everything works fine.

Other requests which I run in this batchUpdate with no issues are are insertTableRows, deleteTableRow, insertText, updateParagraphStyle, updateTextStyle, updateTableColumnProperties. They all work on the same table, so I use the same objectId, but depending on the request I have to specify it as tableObjectId instead of objectId.

Unsure if I am generating a wrong request for the only updateTableCellProperties request I have, or if there is a problem in the Google Slides ruby gem itself, I tried sending just this updateTableCellProperties request from the Google Slides API explorer which has some validation on the request structure. So I sent this updateTableCellProperties batchUpdate request

{
  "requests": [
    {
      "updateTableCellProperties": {
        "objectId": "gf9d8fea71f_22_1",
        "tableRange": {
          "location": {
            "columnIndex": 0,
            "rowIndex": 1
          }
        },
        "fields": "tableCellProperties",
        "tableCellProperties": {
          "tableCellBackgroundFill": {
            "solidFill": {
              "color": {
                "themeColor": "LIGHT1"
              }
            }
          }
        }
      }
    }
  ]
}

And I got this error:

{
  "error": {
    "code": 400,
    "message": "Invalid requests[0].updateTableCellProperties: Invalid field: table_cell_properties",
    "status": "INVALID_ARGUMENT"
  }
}

Why is this updateTableCellProperties request reported as invalid? I am also confused by the output of the error message as it mentions table_cell_properties in snake case, while the documentation only mentions tableCellProperties in camel case, and my request also only mentions tableCellProperties in camel case. I am only aware of the ruby gems translating between snake case and camel case, but this is not relevant to the API Explorer.


Solution

  • The error Invalid field: table_cell_properties originates from the erroneously specified fields property

    See documentation:

    fields

    At least one field must be specified. The root tableCellProperties is implied and should not be specified. A single "*" can be used as short-hand for listing every field.

    So you need to modify fields

    from

    "fields": "tableCellProperties"

    to

    "fields": "tableCellBackgroundFill.solidFill.color"

    or to

    "fields": "*"

    There is a second problem with your request:

    When specifying the table range, it is required to set the properties rowSpan and columnSpan.

    A complete, correct request would be:

    {
      "requests": [
        {
          "updateTableCellProperties": {
            "objectId": "gf9d8fea71f_22_1",
            "tableRange": {
              "location": {
                "columnIndex": 0,
                "rowIndex": 1
              },
              "rowSpan": 1,
              "columnSpan": 1
            },
            "fields": "tableCellBackgroundFill.solidFill.color",
            "tableCellProperties": {
              "tableCellBackgroundFill": {
                "solidFill": {
                  "color": {
                    "themeColor": "LIGHT1"
                  }
                }
              }
            }
          }
        }
      ]
    }