0

I am using the Smart Sheet Python API.

How can I update data completely using the same sheet ID?

My approach was to loop through the columns and delete them (or delete the rowIDs) to clear out the existing sheet. How can I now load new data to the same sheet so I do not have to reshare it, etc?

Is there a more efficient method?

trench
  • 5,075
  • 12
  • 50
  • 80

1 Answers1

2

You could also use the copy_sheet function. This will create a copy of your current sheet, and then using the includes parameter you can specify whether the data is copied, or the shared users are included in the copy.

In your situation, it sounds like you want to have a blank copy of the sheet with the same shared users. That call in Python would look something like this:

copy_response = ss_client.Sheets.copy_sheet(
        sheet_ID,                                 # sheet_id
        ss_client.models.ContainerDestination({
            'destination_type': 'home',           # folder, workspace, or home
            'destination_id': None,               # folder_id
            'new_name': 'newSheetName'
        }),
        'shares'      # includes
)
print(copy_response)

For a complete list of the available includes take a look at the Smartsheet API Docs section for Copy Sheet.

stmcallister
  • 1,682
  • 1
  • 12
  • 21
  • Yeah, I am looking to fully replace the data as per a schedule so Smart Sheet reflects the latest results. I was able to copy the blank sheet and it was shared correctly - I now need to load new data. This seems like it will just loop though, what about the next schedule where I want to replace all of the data again? At that point, I might as well just make a new sheet and delete the old one each time but I am not sure if anyone needs a static Sheet ID for API access. – trench Aug 07 '18 at 12:23
  • Yeah, if you want to keep a cell history you would grab the sheet, get the rowIds, then make a batch call to the PUT /sheets/{sheetId}/rows endpoint to update the rows all at once. That would be the most efficient way to update a group of rows. Docs link to update rows here: https://smartsheet-platform.github.io/api-docs/?python#update-rows – stmcallister Aug 07 '18 at 17:27