I am able to get the Row and Column data from the Smartsheet API JSON response but in it there are no metadata such as _OUTLINELEVEL_ or _ROWNUM_.
When requesting the data from Smartsheet API, I also sent additional params such as:
params = {'include': 'objectValue,objectProperties,format,formula,columnType,options'}
and sent it with the request. But I still do not get any metadata. Specifically, I am trying to get the _OUTLINELEVEL_ column that is present in the Smartsheet.
If I view the Smartsheet online then I can see those columns.
Could someone please help me get this data? Thank you!
The API does support getting the row number for rows within a sheet. For example, the following snippet uses the Smartsheet Python SDK to get a sheet, then iterates through the rows in the response to print out the value of the
row_numberproperty for each row.As far as I know, it's not possible to get the outline level of a row via the Smartsheet API -- unless a user has manually added such a column to the sheet and populated it using a formula -- for example, as described in this Smartsheet Community post: https://community.smartsheet.com/discussion/77827/work-breakdown-structure-wbs-column-formula-configuration#latest.
If this is the case -- i.e., a column has been (manually) created in the sheet and populated with an outline level value -- then you'd obtain that cell value for a row in the same way as you'd obtain the cell value of any other cell within the sheet -- i.e., by using the Get Sheet operation or the Get Row operation and then evaluating the value of that cell within the
rowobject(s) of the API response. For example, the following code snippet uses the Smartsheet Python SDK to get a sheet and then iterates through the rows of the sheet, and for each row prints the value of the cell I'm interested in (i.e., in this example, the value in the column that has column id =5228827298293636).UPDATE: how to determine row hierarchy via API
You can use information within the rows collection of a Get Sheet response to programmatically identify the row hierarchy (i.e., parent-child-sibling relationships) within a sheet.
For example, consider the following sheet:
Please note -- I've manually added (and populated) the last three columns in this sheet to show the data (ID values) that'll be returned for
row.id,row.parent_id, androw.sibling_idin the API response. Further, I've color coded the various ID values to make it easy to see which IDs show up where. As this example shows, theparent_idattribute and thesibling_idattribute for each row in the response indicate where the row appears in the sheet relative to other rows in the sheet. Here's the logic for how these attributes get populated:parent_id:parent_idattribute is present for a row, its value is the ID of the parent row.parent_idattribute is not present for a row, this indicates it's a top-level (i.e., non-indented) row in the sheet.sibling_id:sibling_idattribute is present for a row, its value is the ID of the row that immediately precedes it at the same level of hierarchy (in that location) within the sheet.sibling_idattribute is not present for a row, this indicates that the row is the first row present in that hierarchy (at that location) of the sheet -- i.e., it's either the first top-level (non-indented) row in the sheet or the first child row in that location within the sheet.Here's the Get Sheet API response for the sheet that's shown in the screenshot above.