Search code examples
pythonapismartsheet-api

Smartsheet download attachment via Python


I'm using the simple-smartsheet library for read data from a sheet in Smartsheet and download existing attachments on each row of the sheet.

I can already read the data for each row, however I cannot download existing attachments.

import config
from simple_smartsheet import Smartsheet

sheet = smartsheet.sheets.get(id=config.SHEET_ID) 
for row in sheet.rows:
    attachments = row.attachments
    print(attachments)
        

when executing the above command I get as a result:

[]

simple-smartsheet

I use the simple-smartsheet library as it is the only one that supports python versions 3.6+

my python version 3.7.5


Solution

  • It looks like that library has not implemented logic for dealing with the attachments yet.

    as an alternative to solving this problem I implemented a solution with the code below:

    import requests
    
    
    #token = 'Your smartsheet Token'
    #sheetId = 'Your sheet id'
    
    r = requests.get('https://api.smartsheet.com/2.0/sheets/{sheetId}/rows/{rowId}/attachments', headers={'Authorization': f'Bearer {token}'})
    
    response_json = r.json()
    
    print(response_json)
    
    

    see Get Attachments for more details on handling attachments Smartsheets