node.jssmartsheet-apismartsheet-api-2.0

When adding rows to a new sheet using the Smartsheet Node.js SDK. how would you indent one of the rows you are adding?


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.


Solution

  • First, a few things to understand about specifying row location:

    So, let's say you have a sheet that already contains some rows:

    initial sheet

    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):

    sheet with one new row

    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:

    Add Row response with id property highlighted

    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:

    sheet with new child (indented) row added

    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!