Issue with Fetching Comments from Smartsheet API in Python: 'No Attribute' Errors

I'm trying to extract comments from rows in a Smartsheet sheet using the Smartsheet Python SDK, but I'm encountering several errors, particularly 'AttributeError: 'Sheets' object has no attribute 'get_row_comments'
and 'Attachments' object has no attribute 'list_attachments'
. After some debugging, I realized that the API responses do not contain the expected attributes (like message
or rows
), causing the code to fail.
I have tried multiple combinations, but I still can't get the expected results.
Here’s the code I've been working with:
import smartsheet
Configure your Smartsheet clientaccess_token = 'your_access_token_here' # Make sure to place your access token here
smartsheet_client = smartsheet.Smartsheet(access_token)
sheet_id = 8165655023931268 # This is the sheet ID
def get_comments_from_sheet(sheet_id):
try:
# Get the sheet
response_sheet = smartsheet_client.Sheets.get_sheet(sheet_id)
# Check if the response contains rows if hasattr(response_sheet, 'rows'): rows = response_sheet.rows # Get the rows from the sheet comments = [] # Iterate over each row and get the comments for row in rows: row_id = row.id try: # Get the comments for the row using list_comments response_comments = smartsheet_client.Comments.list_comments(sheet_id, row_id) for comment in response_comments.data: comments.append(comment.text) # Store the comment text except smartsheet.exceptions.SmartsheetException as e: print(f"Error getting comments for row {row_id}: {e}") return comments else: print("Error: Could not retrieve the rows from the sheet.") return [] except smartsheet.exceptions.SmartsheetException as e: print(f"Error retrieving rows from the sheet: {e}") return []Call the function
comments = get_comments_from_sheet(sheet_id)
print("Comments:")
for comment in comments:
print(comment)
Answers
-
@LUMA A I am not sure I understand fully what you are trying to do? do you want row comments, sheet comments, both?
Where in your code is get_row_comments, need the context this is coming from you tell if it is hitting the object correctly.
In general, sheets don't have row comments, rows do. And vice versa rows dont have sheet comments. Have you tried to manually run a curl example of an individual sheet or row to get a comment back and work your object references from there?
https://developers.smartsheet.com/api/smartsheet/openapi/commentsPrincipal Consultant | System Integrations
Prime Consulting Group
Email: info@primeconsulting.com
Follow us on LinkedIn!