JHWelch
JHWelch

Reputation: 45

Iterate through all rows Smartsheet API Python

I am trying to iterate through all the rows in a sheet, but it seems that simply using .rows is limited to returning 100 items.

for temp_row in inventory.rows:
    x += 1
print x #X will always return <= 100

No matter how many items I have in there.

What am I doing wrong?

Edit: Just to clarify, I am trying to do something to every row, not count them, that is just an example of how i noticed it is only grabbing 100 rows.

Upvotes: 2

Views: 2456

Answers (4)

J. Craig Williams
J. Craig Williams

Reputation: 410

The include_all parameters is not part of get_sheet().

The parameter in the Python SDK 2.0 is page_size

and defaults to 100.

my_sheet = smartsheet.Sheets.get_sheet(sheet_id, page_size=5000)

where sheet_id is your sheet's ID.

If you already have the sheet object, you could use

my_sheet.total_row_count

to get the number of rows and use that instead of 5000.

Upvotes: 2

daveskull81
daveskull81

Reputation: 637

It is important to note that when making the request to the Smartsheet API directly rather than via the Python SDK the default response is to include all rows of the sheet without needing to include page or pageSize parameters.

Upvotes: 0

Software2
Software2

Reputation: 2738

By default, get_sheet will return a page with 100 rows. Include the flag: includeAll=true to return all rows.

See the documentation on paging for more info.

Upvotes: 0

Kim Brandl
Kim Brandl

Reputation: 13480

Sounds like perhaps the SDK is utilizing paging when executing the Get Sheet operation -- i.e., it's only returning the first page of results in the response, which defaults to 100 rows. As described in the API docs, page size defaults to 100 rows in the Get Sheet response, unless specified otherwise by the request. (In the docs, see the description for the pageSize and page parameters.)

I'd suggest that you review the SDK for the ability to specify pageSize and/or page when calling the Get Sheet operation.

Upvotes: 0

Related Questions