Python SDK API to add rows with Multi Columns to Smartsheet

cabbsman
cabbsman ✭✭✭✭
edited 06/06/23 in API & Developers

I have a script that reads columns from my source Smartsheet (SS) and gets the values from the columns in the SS and stores them in variables. This code works. Where I am getting stuck is assigning the variables (2 or more columns) to a new row and then adding the row to the destination SS. For example:

Source SS, reads row 1 and assigns the following variables:

  1. hub_site_clli= value from the source SS from the column named "Hub/Site CLLI"
  2. hub_site_name = value from the source SS from the column named "Hub/Site Name".
  3. This code works. Note: The col names on the source SS are the same names of the columns on the destination SS.

Where I'm getting stuck is using the Smartsheet SDK API, assign hub_site_clli and hub_site_name to a new row and then add that row to the destination SS. The destination column IDs for the columns on the destination SS are as follows:

Destination "Hub/Site Name" Column = hub_site_name_col = 123456789123456

Destination Hub/Site CLLI Column = hub_site_clli_col = 5592086053080964


I've looked at and used the Smartsheet's SDK examples but it doesn't show me the entire picture. For example, I can't find any examples on how to update 2 or more columns on a row. They all seem to show just one column in the examples.

THIS IS THE CODE I WROTE TO ASSIGN TO A ROW AND APPEND TO THE DESTINATION SS. WHICH DOESN'T WORK.

-----------------------------------------------------------------------------------------------------   

  hub_site_clli_col = 1088486425710468

  hub_site_name_col = 5592086053080964

  cin_count_total_col = 7568017969860484

  cin_count_deployed_col = 1938518435647364

  cin_count_pending_col = 6442118063017860

  olt_count_total_col = 4190318249332612

  olt_count_deployed_col = 4344071636078468

  olt_count_pending_col = 6595871449763716

  row_id = 7192002709901188 

 import smartsheet

smartsheet_client = smartsheet.Smartsheet(access_token)

  # Initialize client. Uses the API token in the environment variable "SMARTSHEET_ACCESS_TOKEN"

  smartsheet_client = smartsheet.Smartsheet()

  # Make sure we don't miss any error

  smartsheet_client.errors_as_exceptions(True)   

  sheet = smartsheet_client.Sheets.get_sheet(

   4812284098465668)

    

  # Specify cell values for one row

  row_a = smartsheet.models.Row()

  row_a.to_top = True

  row_a.cells.append({

   'column_id': hub_site_name_col,

   'value': "YYUUNN"

   'column_id': hub_site_clli_col,

   'value': "CCIILL123"

  })

   

  # Add rows to sheet

  response = smartsheet_client.Sheets.add_rows(

   4812284098465668,    # destination sheet_id

   [row_a])

WHAT I WAS EXPECTING:

I was expecting a new row on the destination sheet with the hub_site_name and hub_site_clli columns filled in with hub_site_name = YYUUNN and hub_site_clli = "CCIILL123". But instead I got an error:

AND THIS IS THE ERROR I AM GETTING:

 File "./mike.py", line 64, in <module>

  add_row()

 File "./mike.py", line 30, in add_row

  smartsheet_client = smartsheet.Smartsheet(access_token)

 File "/home/mtuccillo/.local/lib/python3.8/site-packages/smartsheet/smartsheet.py", line 154, in __init__

  self._session = pinned_session(pool_maxsize=max_connections)

 File "/home/mtuccillo/.local/lib/python3.8/site-packages/smartsheet/session.py", line 53, in pinned_session

  method_whitelist=Retry.DEFAULT_METHOD_WHITELIST.union(['POST'])))

AttributeError: type object 'Retry' has no attribute 'DEFAULT_METHOD_WHITELIST'

Best Answer

Answers