Home > Blockchain >  Smartsheets Python API cell history from reports
Smartsheets Python API cell history from reports

Time:01-07

I am working with the Python API for Smartsheets. I have been able to get cell history from Sheets but not Reports. Looking here it is not 100% clear if it works with reports.

code to get cell history from sheets that works for me.

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)

Trying to work with Reports

code to get reports?

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)

error when trying to get reports

---------------------------------------------------------------------------
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}}

My question is can you get cell history from reports? If yes how do you do it please? What am I doing wrong with get_cell_history?

CodePudding user response:

In Smartsheet, a Report is just a real-time view of data that's being queried from (and lives in) one or more Sheets. If/when you edit a cell within a Report, what you're actually doing is changing that cell value in the underlying Sheet where that piece of data lives (and when you do so, an entry gets appended to that Sheet cell's history).

i.e., there is no separate/distinct cell history for Reports -- the history of cells that appear within any Report is actually just the history of the corresponding cells in the Sheet(s) where the data's being queried from. This, of course, means that it's not possible to query a Report's cell history via API.

  • Related