I have approximately 40 sheets contained in a folder, and each one of these sheets have rows locked for editing from row 3 to row 45 (approx). I’m trying to make a python script using the smartsheet python API that iterates into each sheet of that folder, and once inside the sheet, unlocks the entire row 3 to 45, and then proceeds with the same action in the next sheet of the folder.
My code is as follows
import smartsheet
access_token = '2vdafasdfadfasdfasdf'
client = smartsheet.Smartsheet(access_token)
# ID de la carpeta que contiene las hojas
folder_id = '123456789' # Reemplaza con el ID de tu carpeta
def unlock_rows(sheet_id, start_row, end_row):
sheet = client.Sheets.get_sheet(sheet_id)
rows_to_update = []
for row in sheet.rows[start_row-1:end_row]:
# Modify the actual Row object
row.locked = False
rows_to_update.append(row) # Append the modified Row object
# Actualiza las filas en la hoja
response = client.Sheets.update_rows(sheet_id, rows_to_update)
if response.message == 'SUCCESS':
print(f"Unlocked rows {start_row} to {end_row} in sheet {sheet.name}")
else:
print(f"Failed to unlock rows in sheet {sheet.name}: {response}")
# Obtén todas las hojas en la carpeta
folder = client.Folders.get_folder(folder_id)
sheets = folder.sheets
# Itera sobre cada hoja y desbloquea las filas
for sheet in sheets:
sheet_id = sheet.id
unlock_rows(sheet_id, 3, 30) # Ajusta el rango de filas si es necesario
print("Rows unlocked successfully.")
when i run the script, i get this result from python
{“response”: {“statusCode”: 400, “reason”: “Bad Request”, “content”: {“errorCode”: 1008, “message”: “Unable to parse request.”, “refId”: “36e3d096-06fd-4042-adc6-aa14c2e4aa77”}}}
Failed to unlock rows in sheet HOJAPRUEBA1: {“result”: {“code”: 1008, “errorCode”: 1008, “message”: “Unable to parse request.”, “name”: “ApiError”, “recommendation”: “Do not retry without fixing the problem. “, “refId”: “36e3d096-06fd-4042-adc6-aa14c2e4aa77”, “shouldRetry”: false, “statusCode”: 400}}
Rows unlocked successfully.
josecal_ism is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.