1

I'm looking to find a sheet via the Smartsheet api and all I have is the name of the sheet. I'm currently solving it like this

sheet_name = 'The sheet I have the name of'
sheets = ss_client.Sheets.list_sheets(include_all=True).data
sheet_id = next(sheet.id for sheet in sheets if sheet.name == sheet_name)

sheet_that_I_want = ss_client.Sheets.get_sheet(sheet_id)

There is a get_sheet method, but it's based of the sheet's id. I feel like there has to be a more direct way of doing this, but I'm not sure what it would be.

af3ld
  • 782
  • 8
  • 30

3 Answers3

5

Sheet names don't have to be unique, so there isn't an endpoint for getting a sheet by name.

However, you could use the search endpoint to search for the sheet by name, and then sift through those results, which will potentially be smaller than iterating over all of your sheets.

sheet_name = "Demo"
search_results = ss_client.Search.search(sheet_name).results

sheet_id = next(result.object_id for result in search_results if result.object_type == 'sheet')
sheet_that_I_want = ss_client.Sheets.get_sheet(sheet_id)
print(sheet_that_I_want)
stmcallister
  • 1,682
  • 1
  • 12
  • 21
1

I found that if I create a sheet and then search for it, it won't be found. It takes a few seconds to update the indexes. Using list_sheets seems to always include the one just created.

RelaxEric
  • 11
  • 2
0

There is a sheet_by_name call.

smartsheet_client = smartsheet.Smartsheet(token)

all_sheets = smartsheet.sheets.Sheets(smartsheet_client)
test_sheet = all_sheets.get_sheet_by_name("Demo")
print(testsheet.name)