Smartsheets API get_cell_history方法仅返回首个实例的value字段问题
Smartsheets API get_cell_history方法仅返回首个实例的value字段问题
Hey there, let's work through this issue you're hitting with the Smartsheets API's get_cell_history() method. It's super odd that you're only seeing the first 'value' entry in the results, while fields like 'modifiedAt' are showing up correctly for all entries—let's break down what might be going on and fix it.
First, let's cover the most common reasons for this behavior:
- Pagination defaults: The Smartsheets API paginates results by default, and if you don't specify otherwise, it might only return the first page of cell history (which could be just one entry). The
get_cell_history()method lets you setpage_sizeto grab more entries at once (max is 100, per API limits). - Incorrect method parameters: Looking at your code snippet, it seems like you might not be targeting a specific cell properly? The
get_cell_history()call needs either acell_id, or bothrow_idandcolumn_idto know exactly which cell's history you want. If you're missing that, it could be pulling partial or unexpected data.
Let's adjust your code to fix these issues:
import smartsheet as ss # Move your token definition before initializing the client (small fix) SMARTSHEET_ACCESS_TOKEN = 'add yours here' smartsheet_client = ss.Smartsheet(SMARTSHEET_ACCESS_TOKEN) sheet = smartsheet_client.Sheets.get_sheet(sheet_id=paperbased) for row in sheet.rows: # Iterate over each cell in the row—history is per-cell, not per-row! for cell in row.cells: # Optional: Skip cells that have no version changes to save API calls if cell.version <= 1: continue # Fetch full history with max page size to get all entries cell_history = smartsheet_client.Cells.get_cell_history( sheet_id=paperbased, row_id=row.id, column_id=cell.column_id, page_size=100 # This pulls up to 100 history entries at once ) # Now loop through each history entry to access all values and timestamps for history_entry in cell_history: print(f"Modified on: {history_entry.modified_at}, Value: {history_entry.value}")
A couple more quick checks to rule out edge cases:
- Double-check the cell's history in the Smartsheets web UI to confirm there are actually multiple value changes. It's possible the
modifiedAtentries are from other metadata updates, not value changes. - If
history_entry.valueis still missing for some entries, tryhistory_entry.display_valueas a fallback—sometimes the API returns formatted display values instead of raw values depending on the cell type.
That should get you seeing all the value entries in the cell history. Let me know if you still run into issues after trying this!
备注:内容来源于stack exchange,提问作者Cam
相关产品推荐
相关产品推荐

