2

I've been able to read sheets, rows, columns, and cells using the Python SDK for Smartsheet, but I haven't been able to actually change/write/update a cell value. I've simplified my code quite a bit and I'm left with this:

import smartsheet
MySS = smartsheet.Smartsheet(MyApiKey)
single_row = MySS.Sheets.get_row(SHEET_ID, ROW_ID)
destination_cell = single_row.get_column(DST_COLUMN_ID)
destination_cell.value = "new value"
single_row.set_column(destination_cell.column_id, destination_cell)
MySS.Sheets.update_rows(SHEET_ID, ROW_ID)

I get the following error when I run this code:

    Traceback (most recent call last):
  File "C:/Users/XXXXXX/Python/Smartsheet/test.py", line 24, in <module>
    MySS.Sheets.update_rows(SHEET_ID, ROW_ID)
  File "C:\Users\XXXXXX\Python\virtualenv PC Smartsheet\lib\site-packages\smartsheet\sheets.py", line 961, in update_rows
    for item in _op['json']:
TypeError: 'long' object is not iterable

I have tried passing the ROW_ID in the last line of code as ROW_ID and [ROW_ID] and [ROW_ID,] but get the same error nonetheless.

I'm using this as my reference: http://smartsheet-platform.github.io/api-docs/?python#update-row(s)

What am I doing wrong?

doron
  • 258
  • 2
  • 11
  • Did you use a print statement to check on the type of destination cell, destination cell value. SHEET_ID and ROW_ID can't be it, since they worked when you were reading the cell. – roadrunner66 Apr 01 '16 at 01:04
  • `print type(destination_cell` gives me ``. Before I try changing the cell, I get a type of `` and after I change it, I get a type of `` – doron Apr 01 '16 at 01:08
  • I don't know the syntax of smartsheets set_column, but could it be you are expected to just set the value? – roadrunner66 Apr 01 '16 at 01:10
  • The API documentation that I linked in the question shows this example: `row_a.set_column(cell_a.column_id, cell_a)`. I'm not sure why; I'm just following the docs. There are four different examples of set_column that follow this syntax. – doron Apr 01 '16 at 01:20

1 Answers1

4

You're so close! Rather than sending the ROW_ID to the update_rows() you actually want to send the row object in a list.

So, in your case, you would just want to change your last line to be

MySS.Sheets.update_rows(SHEET_ID, [single_row])
stmcallister
  • 1,682
  • 1
  • 12
  • 21
  • Thanks @stmcallister for pointing out my mistake! I fixed that but now the row is not getting updated. Using the code above with your correction, I get back `"code": 1062, "name": "InvalidRowLocationError"` in the response from the update_rows command. Nothing gets updated. I further debugged by printing the row right after the set_column command and the cell value is not being updated. **Should I post this as a new question?** – doron Apr 01 '16 at 14:46