0

Everytime I use the smart-sheet-sdk code example, it creates a new Smartsheet with the same name and a new ID. How can I define which Smartsheet has to be updated? I just don“t want random sheets to be created every time.

Thanks in advance for all your help!

Sample code can be found here: https://github.com/smartsheet-samples/python-read-write-sheet/blob/master/python-read-write-sheet.py

FOttolini
  • 1
  • 1

1 Answers1

0

To update a specific sheet, you'll want to provide the Sheet's ID. You can find that by opening the sheet and going to File (top left) > Properties. The ID of the item you're updating is almost always the first argument passed to the method you're using to update Smartsheet.

I've put an example below. In this example, we are getting a sheet based on a provided Sheet ID. Then we're checking the column ID of the leftmost column on the sheet, and adding a new row to the bottom with "Test Value" in that column.

import smartsheet
API_TOKEN = "<<YOUR API TOKEN>>"
SHEET_ID = 123456789 # Replace with your Sheet ID

smartsheet_client = smartsheet.Smartsheet(API_TOKEN)

# Get the sheet so that we can reference its columns
sheet = smartsheet_client.Sheets.get_sheet(SHEET_ID)

# Create/define a new row
new_row = smartsheet.models.Row()
new_row.to_bottom = True # Will add the row to the bottom of the sheet

# Add a value to the leftmost column of the sheet.
new_row.cells.append({
    'column_id': sheet.columns[0].id # ID of the leftmost column. Column "0".
    'value': "Test Value" # Whatever value you want
})

# Will POST the row to the sheet.
smartsheet_client.Sheets.add_rows(sheet.id, new_row)