1

I had the column in the smartsheet as 'Allowing multiple contacts to be selected'.

I am using simple_smartsheet package (https://pypi.org/project/simple-smartsheet/) but I cannot seems to find in the internet that anyone adding multiple contact using this package.

Below is the piece of code that i tried:

from simple_smartsheet import Smartsheet
from simple_smartsheet.models import Sheet, Column, Row, Cell, ColumnType

#%%
access_token='XXX'
smartsheet = Smartsheet(access_token)
sheet_name = 'test'

sh = smartsheet.sheets.get(sheet_name)

new_rows = [
    Row(
        to_top=True,
        cells=[
            Cell(column_id=released_by.id, value=[{'objectType': 'CONTACT',
                                                    'email': 'xxx.yyy@westrac.com.au',
                                                    'name': 'xxx yyy'},
                                                {'objectType': 'CONTACT',
                                                    'email': 'aaa.bbb@westrac.com.au',
                                                    'name': 'aaa bbb'}])
        ],
    ),
]

#new_rows.append(Row(to_top=True,cells=sh.make_cells(row_value)))
smartsheet.sheets.add_rows(sh.id, new_rows)

But I got this error:

SmartsheetHTTPClientError: HTTP response code 400 - Error code 1008 - Unable to parse request. The following error occurred: Field "value" was not parsable. value must be a primitive type
 at [Source: java.io.PushbackInputStream@786472ed; line: 1, column: 241].

I am not quite sure where did i do wrong. Any thoughts?

martineau
  • 119,623
  • 25
  • 170
  • 301
kevin hiew
  • 96
  • 1
  • 7

3 Answers3

0

From the python doc to the original doc you can see that the Cell class only accept as value either a string a boolean or a number

So this should work:

new_rows = [
    Row(
        to_top=True,
        cells=[
            Cell(column_id=released_by.id, value="your value")
        ],
    ),
]
pierresegonne
  • 436
  • 1
  • 4
  • 15
  • Thanks for the response. That didn't work because the column has a property that allows for multiple contact. It works if the column property is set to only single contact is allowed. Any idea? – kevin hiew Apr 15 '20 at 10:31
  • The column or the cell? Why would a single cell have different values? – pierresegonne Apr 15 '20 at 17:24
  • if the column is set to allow multiple contact in one cell. You can put two contacts or more contacts in that single Cell. i still haven't solved it yet but i just switch to single contact for now. – kevin hiew Apr 17 '20 at 04:35
0

You were close and this was a pain. This is working for me...example for multi contact and single...

#build to update a cell
new_cell = smartsheet_client.models.Cell()
new_cell.column_id = pasteCol
new_cell.object_value = {"objectType":"MULTI_CONTACT", "values":[{"name":"rOB","email":"test@test.com"}, {"name":"rob","email":"rob@test.com"}]}

#this will work on single select
#new_cell.object_value = {'objectType': 'CONTACT','email': 'test@test.com', 'name': 'test'} 
new_cell.strict = True
print(new_cell)

#append to update
get_row = smartsheet.models.Row()
get_row.id = rowID
get_row.cells.append(new_cell)
updated_row = smartsheet_client.Sheets.update_rows(sheet_id,[get_row])    
0

Create the list of values as text delimited (I created a function to convert it to a correct formatted string because SS is very strict)

Initialize the row as usual.

Create the cell adding the "objectType" option as "MULTI_PICKLIST" and add to the row (this should be inside "object_value")

new_row_add.cells.append({'column_id': col_id, 'object_value': {'objectType': 'MULTI_PICKLIST', 'values': new_list}, 'strict': True})

Add the row as usual This also works for row updates