J. Craig Williams
J. Craig Williams

Reputation: 410

Smartsheet API get_sheet (Python) filters not working

I'm using Python 3.52 , Smartsheet API SDK 2.0.10.

The get_sheet (in sheets.py) has three 'filters' which are lists of integers for

  1. row_numbers,
  2. column_ids, and
  3. row_ids.

I can get none of them to work, together or separately. For example,

row_numbers = [2, 13]
sheet = smartsheet.Sheets.get_sheet(sheet_id, row_numbers)
for row in sheet.rows:
    print(row.row_number)

returns all of the rows, not just 2 and 13. Am I doing something wrong or is this a bug?

Craig

Upvotes: 0

Views: 1073

Answers (2)

timwells
timwells

Reputation: 341

Reputation won't let me comment yet, but Steve W is on the right track.

See https://docs.python.org/3/reference/expressions.html#calls for a description of how Python assigns arguments to parameters list. In your example row_numbers is being assigned to the include parameter. To do what you want you'll have to use a combination of positional(sheet_id) and keyword(row_numbers) arguments. All other arguments will use defaults as specified by function definition.

This code works as expected, returning the 2nd and 13th rows in the sheet:

row_numbers=[2,13]
sheet = smartsheet.Sheets.get_sheet(sheet_id, row_numbers=row_numbers)

Upvotes: 0

Steve Weil
Steve Weil

Reputation: 873

The full method signature is get_sheet(sheet_id, include=None, exclude=None, row_ids=None, row_numbers=None, column_ids=None, page_size=100, page=1)

See docs

So in your case you'd need something like smartsheet.Sheets.get_sheet(sheet_id, None, None, None, row_numbers )

Upvotes: 1

Related Questions