How to add a row with a CONTACT_LIST column using API (python)
mortonj
✭
I am trying to add a row to an existing sheet with a CONTACT_LIST column. As far as I can tell, I am following the syntax properly, but I am always getting a validation error in the response.
Can someone provide a sample request for this operation, using python.
I found this similar question, and it says it was answered, but no solution was provided.
Answers
-
Hi @mortonj
The Python code will add rows with a CONTACT_LIST column cell and a Multiple_CONTACT_LIST column cell if the sheet specified by sheet_id has such columns. (The code uses smartsheet-python-sdk.)
pip install smartsheet-python-sdk
import smartsheet access_token = 'your access token' smartsheet_client = smartsheet.Smartsheet(access_token) sheet_id = 1234567890123456 sheet = smartsheet_client.Sheets.get_sheet(sheet_id) contact_list_column_id = next((column.id for column in sheet.columns if column.type == "CONTACT_LIST"), None) multiple_contacts_column_id = next((column.id for column in sheet.columns if column.version == 1), None) members = [ {"name": "Jane Doe", "email": "jane.doe@sample.com"}, {"name": "John Doe", "email": "john.doe@sample.com"}, {"name": "John Smith", "email": "john.smith@sample.com"}, {"name": "Jane Smith", "email": "jane.smith@sample.com"}, ] rows_to_add = [] multi_contacts = [] for member in members: new_row = smartsheet.models.Row() if contact_list_column_id: contact_cell = smartsheet_client.models.Cell() contact_cell.column_id = contact_list_column_id member['objectType'] = 'CONTACT' contact_cell.object_value = member new_row.cells.append(contact_cell) if multiple_contacts_column_id: multi_contacts.append(member) multiple_contact_cell = smartsheet_client.models.Cell() multiple_contact_cell.column_id = multiple_contacts_column_id multiple_contact_cell.object_value = {"objectType": "MULTI_CONTACT", "values": multi_contacts} new_row.cells.append(multiple_contact_cell) if contact_cell or multiple_contact_cell: rows_to_add.append(new_row) if len(rows_to_add) > 0: # Add rows to sheet response = smartsheet_client.Sheets.add_rows( sheet_id, # sheet_id rows_to_add)
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.8K Get Help
- 437 Global Discussions
- 138 Industry Talk
- 470 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 65 Community Job Board
- 486 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives