First time posting here, so I apologize for any "grievances" and appreciate your patience. I'm working on a process that creates new sheet, and then parses an array of row Objects to be added to the new sheet.
https://smartsheet.redoc.ly/#operation/rows-addToSheet
The area I'm struggling with is including a property to indent the row being added. The indent property is indicated in the specify row location resource in the documentation.
https://smartsheet.redoc.ly/#section/Specify-Row-Location
Here is what i thought my row object should look like:
const myRowObj = [
{
toBottom: true,
cells: [
{
columnId: 3811134080870276,
value: 'no indent',
},
{
columnId: 8314733708240772,
value: "this line has no indent"
}
]
},
{
toBottom: true,
indent: 1,
cells: [
{
columnId: 3811134080870276,
value: 'indent sent to 1'
},
{
columnId: 8314733708240772,
value: "this line has an indent"
}
]
}
]
... however when using this row Object, I get an error back indicating that indent should be used by itself in a request.
{
statusCode: 400,
errorCode: 1062,
message: "Invalid row location: Use 'indent' by itself. You cannot use other location specifiers in the same request.",
refId: '9abmoi4dizfj',
detail: { index: 0 }
}
... when using the above code, and leaving out the indent
property, the rows are successfully processed, but no indentation takes place obviously. When removing the toBottom
properties from each row and using indent
in the second row instead, i get a new error:
{
statusCode: 400,
errorCode: 1123,
message: 'Specifying multiple row locations is not yet supported. Each row must use the same row location attribute and value (toBottom, toTop, parentId, siblingId,
above)',
refId: 'wbpkbx4qw7oz',
detail: { index: 1 }
}
This, of course, contradicts the original instruction for the first error. Including the indent
property on both rows, returns the first error. So, after spending around 4 hours trying to fidget with this much needed feature, I wanted to ask if anyone else has had success using the indent
property when adding rows to a sheet. I'm hoping someone could share a sample of how the row object with an indent is structured, since the documentation lacks a working sample.
Thanks in advance for your help,
Don V.
First, a few things to understand about specifying row location:
By default, new rows are added to the bottom of the sheet -- so it's not necessary to specify the toBottom
property if you want new rows to be added to the bottom of the sheet.
The indent
property can only be used to specify indent level for existing rows in a sheet -- you can't use it in a request that adds new rows to a sheet.
When using the Add Rows operation to add new rows to a sheet, all new rows specified in the request must use the same row location specifier attributes. This means that you can't use a single Add Rows request to add a parent row and a child row indented under that row all at the same time -- because those rows are in different locations (one is indented, the other is not).
So, let's say you have a sheet that already contains some rows:
If you want add two rows to the bottom of a sheet, where the first row is a parent row (with no indentation) and the second row is a child row (with indentation), then you'll need to do so as a 2-step process (i.e., 2 separate Add Row(s) requests):
Step 1 (add parent row):
Issue the Add Rows request to add the first row (with no indentation).
POST https://api.smartsheet.com/2.0/sheets/3932034054809476/rows
[
{
"cells": [
{
"columnId": 6101753539127172,
"value": 4
},
{
"columnId": 5228827298293636,
"value": "parent row (no indent)"
}
]
}
]
After this request is issued, the sheet contains this new row (no indentation):
Step 2 (add child row):
The API response from the previous Add Row(s) request will contain the ID of the row that it added:
When you issue the next Add Row(s) request, you'll specify this ID value as the parentId
for the row you're adding -- this is how you tell Smartsheet to add the new row as a child (i.e., indented) row under the specified row.
POST https://api.smartsheet.com/2.0/sheets/3932034054809476/rows
[
{
"parentId": 7046650170566532,
"cells": [
{
"columnId": 6101753539127172,
"value": 5
},
{
"columnId": 5228827298293636,
"value": "child row (with indent)"
}
]
}
]
After this request is issued, the sheet contains the new child (i.e., indented) row:
Hope this is helpful. If you need additional clarification please add a comment to this answer; if this successfully addresses your question, please mark this answer as accepted (so that others are more likely to benefit from this info in the future). Thanks!