Smartsheet API to create csv

Hi,

I am trying to create csv file using smartsheet -python-sdk.. i am getting following error

   response.save_to_file()

AttributeError: 'Error' object has no attribute 'save_to_file'


on further debugging i found that save_to_file module does not exist.

Is there any other way to export smartsheet to csv format via api call from python ?


Thanks in advance.

Answers

  • Genevieve P.
    Genevieve P. Employee Admin

    Hi @ashwanikk

    Is it possible that you don't have a download_directory_path specified?

    There's an example of the Python request for a CSV on the right in the API Documentation for Get Sheet (Sample 4): https://smartsheet.redoc.ly/tag/sheets#operation/getSheet

    # Sample 4: Get sheet as CSV
    smartsheet_client.Sheets.get_sheet_as_csv(
      1531988831168388,           # sheet_id
      download_directory_path)
    

    Let me know if this helped or not!

    Cheers,

    Genevieve

  • Parker Oxford
    Parker Oxford ✭✭✭✭✭

    I am currently having the same issue, I have the pathway specified and when I go to run it, I get the same error. I have attached the code below.

    import smartsheet
    
    # smartsheet access token
    access_token = 'XXXXXXXXXXX'
    
    smartsheet_client = smartsheet.Smartsheet(access_token)
    sheet_id = 'XXXXXXXXXXXXXX'
    path = r'C:\path\to\folder'
    
    smartsheet_client.Sheets.get_sheet_as_pdf(
        sheet_id,
        path,
        'A4',
        'test_pdf.pdf'
    )
    
    

    Please let me know if I am approaching this wrong or if there is a better solution for this.


    Also, I'd like it to export in the calendar view, is it possible to accomplish this?

  • Alex Argumedo
    Alex Argumedo ✭✭✭✭

    This worked for me:

    ###########

    import smartsheet

    smart = smartsheet.Smartsheet()

    destf = "E:\\Scripting\\Python\\Downloads\\"

    pa161 = smart.Sheets.get_sheet_as_pdf( <insert ID>, destf,'A1', 'test.pdf' )