报告中的Smartsheets Python API单元格历史记录

xytpbqjk  于 2023-01-10  发布在  Python
关注(0)|答案(1)|浏览(90)

我正在使用Smartsheets的Python API。我已经能够从工作表中获得单元格历史,但不能从报表中获得。看here,它是否能与报表一起工作并不是100%清楚。
从床单上获取细胞历史记录的代码。

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

my_col_id = xxxx
my_sheet_id = xxxx

sheet = smartsheet_client.Sheets.get_sheet(sheet_id=my_sheet_id )
output_list = []

# get the cell history
for row in sheet.rows:
    cell_history = smartsheet_client.Cells.get_cell_history(my_sheet_id, row.id, my_col_id, include_all=True)
    try:
        for i in cell_history.data:
            print([row.row_number, row.id, i.modified_at, i.modified_by.name, i.value, i.column_id])
    except Exception as e:
        print(e.message)

尝试使用报表

获取报告的代码?

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

my_col_id = xxxx
my_report_id = xxxx

sheet = smartsheet_client.Reports.get_report(report_id=my_report_id)
output_list = []

# get the cell history
for row in sheet.rows:
    cell_history = smartsheet_client.Cells.get_cell_history(my_report_id, row.id, my_col_id, include_all=True)
    try:
        for i in cell_history.data:
            print([row.row_number, row.id, i.modified_at, i.modified_by.name, i.value, i.column_id])
    except Exception as e:
        print(e.message)

尝试获取报告时出错

---------------------------------------------------------------------------
ApiError                                  Traceback (most recent call last)
C:\Users\xxxx\AppData\Local\Temp/ipykernel_16636/3969747724.py in <module>
---> 36     cell_history = smartsheet_client.Cells.get_cell_history(sheet_id=All_papers_including_PFP, row_id=row.id, column_id=level_col, include_all=True)
     37     # print(row.id)
     38     # print(cell_history.data)

c:\Users\xxxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\smartsheet\cells.py in get_cell_history(self, sheet_id, row_id, column_id, include, page_size, page, include_all, level)
     69 
     70         prepped_request = self._base.prepare_request(_op)
---> 71         response = self._base.request(prepped_request, expected, _op)
     72 
     73         return response

c:\Users\xxxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\smartsheet\smartsheet.py in request(self, prepped_request, expected, operation)
    248         if isinstance(native, self.models.Error):
    249             the_ex = getattr(sys.modules[__name__], native.result.name)
--> 250             raise the_ex(native, str(native.result.code) + ': ' + native.result.message)
    251         else:
    252             return native

ApiError: {"result": {"code": 1006, "errorCode": 1006, "message": "Not Found", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "1qz12xxyf8tuh", "shouldRetry": false, "statusCode": 404}}

我的问题是你能从报告中得到手机历史记录吗?如果可以,你是怎么做到的?我在get_cell_history上做错了什么?

92vpleto

92vpleto1#

在Smartsheet中,报表只是从一个或多个工作表中查询(并存在于其中)的数据的实时视图。如果/当您编辑报表中的单元格时,您实际上是在更改该数据所在的基础工作表中的单元格值(当您这样做时,会将一个条目追加到该工作表单元格的历史记录中)。
也就是说,报表没有单独的/不同的单元格历史--任何报表中出现的单元格历史实际上只是从中查询数据的工作表中相应单元格的历史。当然,这意味着不可能通过API查询报表的单元格历史。

相关问题