Using smartsheet-python-sdk to put data back into Smartsheet

bellayav
bellayav
edited 05/10/22 in API & Developers

I used the smartsheet-python-sdk (and unique API key from Smartsheet) to automatically pull data from Smartsheet into my Python script along with other data sources to create new feature-engineered columns. Is there an automatic way to now put these new columns I created back into the same Smartsheet I initially pulled data from using the smartsheet-python-sdk? Thank you!

Answers

  • ericncarr
    ericncarr ✭✭✭✭✭
    edited 05/11/22

    I re-read your question and the answer is still yes but how you go about it would be different.

    Add columns: https://smartsheet-platform.github.io/api-docs/?python#add-columns

    I would assume, depending on how many columns you have, you could use a for loop to populate the necessary information in the column specification.

    Here's an example where I took the columns from one sheet, put them in a list, and then wrote them to another sheet in a batch.

    column_to_add = [ ]

    for column in new_sheet.columns:

      column_model = smartsheet.models.Column({'title': column.title, 'type': 'TEXT_NUMBER', 'index': col_index})

      columns_to_add.append(column_model)

    new_columns = ss_client.Sheets.add_columns(target sheet ID, columns_to_add) 


    If you need to populate those rows with specific data that is also possible by updating rows, but it could get more complex (I think) depending on what exactly you're trying to do.