How to retrieve the only past 5 days created row using Smartsheet API
Hi All,
I'm exploring the Smartsheet API. My use case to extract past 5days newly created records from my "ABC1231231" Sheet using Smartsheet API call. Kindly advise me which API method i need to use and how to use the Date query filter?
Answers
-
To extract records from a Smartsheet that were created in the past 5 days, you would typically use the
GET /sheets/{sheetId}/rows
endpoint, applying query parameters to filter rows based on their creation dates. However, the Smartsheet API does not directly support filtering rows by creation date through query parameters.To achieve this, you can:
- Retrieve all rows from the sheet using the
GET /sheets/{sheetId}/rows
endpoint. - Filter the retrieved rows on the client side (in your application code) based on their
createdAt
property.
Here's how you could do it in pseudocode, assuming you've fetched the rows into a variable called
rows
:import datetime
# Your sheet ID
sheet_id = "ABC1231231"
# Calculate the date 5 days ago from today
five_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=5)
# Filter rows created in the last 5 days
new_rows = [row for row in rows if datetime.datetime.strptime(row['createdAt'], '%Y-%m-%dT%H:%M:%SZ') > five_days_ago]
# new_rows now contains only the rows created in the past 5 days
Please replace
"ABC1231231"
with your actual sheet ID and adjust the datetime parsing/formatting as per your actual data structure and requirements.Remember, this approach requires fetching all rows from the server first and then filtering them locally, which might not be the most efficient method for sheets with a large number of rows. If you have a date column in your sheet that records the creation date, you could instead use the column filter functionality in the Smartsheet UI to directly view or export the filtered rows.
- Retrieve all rows from the sheet using the
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.1K Get Help
- 414 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 141 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives