So as a workaround to difficulties creating a new sheet with groups I am trying to create and collapse these groups in a separate call to batchUpdate. I can call request an addDimensionGroup
successfully, but when I request updateDimensionGroup
to collapse the group I just created, either in the same API call or in a separate one, I get this error:
{
"error": {
"code": 400,
"message": "Invalid requests[1].updateDimensionGroup: dimensionGroup.depth must be \u003e 0",
"status": "INVALID_ARGUMENT"
}
}
But I'm passing depth as 0 as seen by the following JSON which I send in my request:
{
"requests":[{
"addDimensionGroup":{
"range":{
"dimension":"ROWS",
"sheetId":0,
"startIndex":2,
"endIndex":5}
}
},{
"updateDimensionGroup":{
"dimensionGroup":{
"range": {
"dimension":"ROWS",
"sheetId":0,
"startIndex":2,
"endIndex":5
},
"depth":0,
"collapsed":true
},
"fields":"*"
}
}],
"includeSpreadsheetInResponse":true}',
...
I'm not entirely sure what I am supposed to provide for "fields", the documentation for UpdateDimensionGroupRequest says it is supposed to be a string ("string ( FieldMask format)"), but the FieldMask definition itself shows the possibility of multiple paths, and doesn't tell me how they are supposed to be separated in a single string.
What am I doing wrong here?
The error message is actually instructing you that the
dimensionGroup.depth
value must be> 0
:If you call
spreadsheets.get()
on your sheet, and request only theDimensionGroup
data, you'll note that your created group is actually at depth1
:This makes sense, since the depth is (per API spec):
Note that any given particular
DimensionGroup
"wholly contains its own range" by definition.If your goal is to change the status of the
DimensionGroup
, then you need to set itscollapsed
property:For this particular
Request
, the only attribute you can set iscollapsed
- the other properties are used to identify the desiredDimensionGroup
to manipulate. Thus, specifyingfields: "*"
is equivalent tofields: "collapsed"
. This is not true for the majority of requests, so specifyingfields: "*"
and then omitting a non-required request parameter is interpreted as "Delete that missing parameter from the server's representation".To change a
DimensionGroup
'sdepth
, you must add or remove otherDimensionGroup
s that encompass it.