You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Smartsheets Python API能否从Reports获取单元格历史记录?

问题解答

能否通过Smartsheets Python API从Reports获取cell history?

不能直接通过Report ID调用单元格历史接口,因为Reports本质是源Sheet的视图,单元格的修改历史仅存储在对应的源Sheet中,而非Report本身。你遇到的404错误(code 1006)就是因为传入了Report ID而非Sheet ID,API无法找到对应的资源。

正确的实现方法

要获取Report中单元格的历史,需要从Report返回的行数据中提取源Sheet ID和源行ID,再用这两个ID调用get_cell_history接口。

修改后的代码如下:

import smartsheet as ss
smartsheet_client = ss.Smartsheet(SMARTSHEET_ACCESS_TOKEN)
smartsheet_client.errors_as_exceptions()

my_col_id = xxxx
my_report_id = xxxx

# 获取Report数据
report = smartsheet_client.Reports.get_report(report_id=my_report_id)
output_list = []

# 遍历Report中的行,提取源Sheet和源行信息
for row in report.rows:
    # 关键:获取源Sheet ID和源行ID
    source_sheet_id = row.source_sheet_id
    source_row_id = row.source_row_id
    
    try:
        # 使用源Sheet和源行ID获取单元格历史
        cell_history = smartsheet_client.Cells.get_cell_history(
            source_sheet_id, 
            source_row_id, 
            my_col_id, 
            include_all=True
        )
        for i in cell_history.data:
            print([row.row_number, source_row_id, i.modified_at, i.modified_by.name, i.value, i.column_id])
    except Exception as e:
        print(str(e))

原代码的错误点

你之前的代码直接将my_report_id传入get_cell_history的sheet_id参数,但该接口仅接受Sheet ID,不支持Report ID,因此触发了"Not Found"的404错误。

内容的提问来源于stack exchange,提问作者Cam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 02:05:18