Reputation: 3414
I need to get the last modified timestamp property of a sheet using Smartsheet API 2.0 (preferably Python SDK). Ref:
Using Sheets.list_sheets
I am able to get the 'modifiedAt' property (along with other properties) for all the sheets that I have access to.
Using Sheets.get_sheet(sheet_id
) I get all the data (rows, columns) for the specified sheet.
How do I get only the 'modifiedAt' (it's OK if some other small properties are also present) for a specific sheet with a known sheet ID. I don't want the row, column, cell information to be present in the API response.
Upvotes: 2
Views: 1266
Reputation: 3414
I wrote to Smartsheet support team and their answer served my purpose.
Thanks for contacting Smartsheet Support. In order to narrow down the response that you're getting, you can use the exclude parameter: http://smartsheet-platform.github.io/api-docs/#query-strings. In my testing, I excluded all rows and columns where columnIds=0 and rowIds=0. That left me with only the Sheet information, which includes the modifiedAt for the sheet. You may be able to limit it further, but the result I got from this was pretty short and sweet.
(Python SDK example)
response = ss_client.Sheets.get_sheet(MY_SHEET_ID, column_ids='0', row_ids = '0')
Using the above parameters, I was able to exclude all the sheet data and got only the metadata (which included modifiedAt property).
Basically my intention was to run a sync script periodically and store the Smartsheet data into my local db. I wanted the API response to skip the actual Sheet data (rows, columns, cells) if nothing would have changed since the last execution. Another nifty way of achieving this to use the ifVersionAfter parameter.
ifVersionAfter (optional): If version specified is still the current sheet version, then returns an abbreviated Sheet object with only the sheet version property. Otherwise, if the sheet has been modified, returns the complete Sheet object. Intended to allow clients with a cached copy to make sure they have the latest version.
last_version_fetched = 7724
response = ss_client.Sheets.get_sheet(MY_SHEET_ID, if_version_after=last_version_fetched)
Upvotes: 3
Reputation: 1033
The Get Sheet call will always return the content (row, column, data) from a specific sheet. While there is an 'exclude' query parameter that can filter out some properties, it does not work on the primary sheet data returned from the /sheets/{sheetId}
endpoint.
The Sheets.list_sheets
call seems like the easier route if you only need the modifiedAt property. I would use that one then iterate over the results until you find the matching id.
Upvotes: 0