1

How do I take a list of values, iterate through it to create the needed objects then pass that "list" of objects to the API to create multiple rows?

I have been successful in adding a new row with a value using the API example. In that example, two objects are created.

row_a = ss_client.models.Row()
row_b = ss_client.models.Row()

These two objects are passed in the add row function. (Forgive me if I use the wrong terms. Still new to this)

response = ss_client.Sheets.add_rows(
2331373580117892,       # sheet_id
[row_a, row_b])

I have not been successful in passing an unknown amount of objects with something like this.

 newRowsToCreate = []
 for row in new_rows:
     rowObject = ss.models.Row()
     rowObject.cells.append({
       'column_id': PM_columns['Row ID Master'],
       'value': row
     })
     newRowsToCreate.append(rowObject)

 # Add rows to sheet
 response = ss.Sheets.add_rows(
   OH_MkrSheetId,       # sheet_id
   newRowsToCreate)

This returns this error:

{"code": 1062, "errorCode": 1062, "message": "Invalid row location: You must 
use at least 1 location specifier.",

Thank you for any help.

Tyler Baker
  • 23
  • 1
  • 7

3 Answers3

3

From the error message, it looks like you're missing the location specification for the new rows.

Each row object that you create needs to have a location value set. For example, if you want your new rows to be added to the bottom of your sheet, then you would add this attribute to your rowObject.

rowObject.toBottom=True

You can read about this location specific attribute and how it relates to the Python SDK here.

stmcallister
  • 1,682
  • 1
  • 12
  • 21
0

To be 100% precise here I had to set the attribute differently to make it work:

rowObject.to_bottom = True

I've found the name of the property below:

https://smartsheet-platform.github.io/smartsheet-python-sdk/smartsheet.models.html#module-smartsheet.models.row

0

To be 100% precise here I had to set the attribute differently to make it work:

Yep, the documentation isn't super clear about this other than in the examples, but the API uses camelCase in Javascript, but the same terms are always in snake_case in the Python API (which is, after all, the Pythonic way to do it!)

chiashurb
  • 31
  • 4