0

I want to script the download of 8 sheets using the module smartsheet-python-sdk.

Later I want to automate the download scheduled at a specific time once a week with Windows Task Scheduler.

But I have trouble with the Python script downloading the sheets via API.

This is what I have in a .py file.

import os, smartsheet

token=os.environ['SMARTSHEET_ACCESS_TOKEN']

smartsheet_client = smartsheet.Smartsheet(token)

smartsheet_client.errors_as_exceptions(True)

smartsheet_client.Reports.get_report_as_excel(
  8729488427892475,
  'C:/Desktop',
  'MyFileName.xlsx'
)
  • Given your report-id you want to download a single XLS file using the opreation [`get-report-as-excel-csv`](https://smartsheet-platform.github.io/api-docs/?python#get-report-as-excel-csv). What is not working as expected, any errors you can post? – hc_dev Jun 09 '22 at 20:08

1 Answers1

1

I notice a couple of issues with the code you've posted.

First, smartsheet_client.Reports.get_report_as_excel should be smartsheet_client.Sheets.get_sheet_as_excel if you're wanting to retrieve a sheet (not a report).

Next, try specifying the full path for where Desktop actually lives on the file system. i.e., instead of just using the alias C:\Desktop -- specify the actual file system path, for example: c:/users/USERNAME/desktop (on a Windows machine) where USERNAME is the name of the currently logged in user. You can also derive the logged-in user dynamically, see How to make Python get the username in windows and then implement it in a script.

The following code successfully downloads the specified sheet to my Desktop, with the filename MyFileName.xlsx. (I'm logged in as kbrandl so the path to my Desktop is specified as: c:/users/kbrandl/desktop.)

sheetId = 3932034054809476

smartsheet_client.Sheets.get_sheet_as_excel(
    sheetId,
    'c:/users/kbrandl/desktop',
    'MyFileName.xlsx'
)
hc_dev
  • 8,389
  • 1
  • 26
  • 38
Kim Brandl
  • 13,125
  • 2
  • 16
  • 21
  • OMG! That worked! I changed it to: smartsheet_client.Sheets.get_sheet_as_excel and that did it. (I intentionally left out the "user/" part of the desktop address b/c it had my ID) – Charles Shin Jun 09 '22 at 21:10
  • Happy I could help. Can you please mark my answer as "Accepted" (and also 'upvote' the answer, if you want to)? Doing so will make others more likely to benefit from this info in the future. Thanks! – Kim Brandl Jun 09 '22 at 23:25
  • Great to have some Smartsheet users that know and spot the difference between _report_ and _sheet_ plus have Windows to reproduce it. – hc_dev Jun 10 '22 at 07:02