My task is to move 3500+ rows to an archive sheet every two weeks. I'm using the python SDK Sheets.move_rows() command but am running into a timeout error (4002) after just 250 rows (granted there are a lot of columns). Can anyone recommend a better method than telling python to loop through the list, moving 250 at a time? 3500 / 250 = a lot...
I attempted to use the automation workflow first but it threw an error too (it didn't say which).
The project allows the rows to be added and edited until a supervisor marks the range of rows as complete on Monday afternoon every other week. Once completed all the rows need to be archived.
Python Script: (my apologies to all the professionals - I'm a newbie)
import os, smartsheet
token = '[API TOKEN]'
os.environ['SMARTSHEET_ACCESS_TOKEN'] = token
sheet_id_Intake = '...........0000' # Sheet_ID can be found by going to the Sheet -> Properties -> Sheet ID
sheet_id_Archive = '...........0001'
filter_ReadytoArchive # this is a sheet filter created in smartsheets. I used a postman api call to get the filterID
# Initializes a smartsheets instance
Sheet = smartsheet.Smartsheet()
Sheet.errors_as_exceptions(True)
# gets the list of rows needing to be archived from the intake sheet
archive_rows = Sheet.Sheets.get_sheet(sheet_id_Intake, exclude=["filteredOutRows"], filter_id=Filter_ReadytoArchive)
# creates a python list of the row id's - a maximum of 250 rows
row_list = []
i=0
for row in archive_rows.rows:
if i >= 250:
break
else:
row_list.append(row.id)
i += 1
# sends request to move rows
try:
response = Sheet.Sheets.move_rows(sheet_id_Intake,smartsheet.models.CopyOrMoveRowDirective({'row_ids': row_list,'to': smartsheet.models.CopyOrMoveRowDestination({'sheet_id': int(sheet_id_Archive )})})) # note I had to convert the Archive sheet id to an integer - for some reason it wouldn't take a string like everywhere else
print(response)
except Exception as e:
print (e)