Is there any way to Automate to upload files from local to the specific row in smartsheet in bulk?

edited 03/15/24 in API & Developers


I tried to write a python code to upload files from local to rows in smartsheet in bulk. The is executed without any output.

Could someone please help me on it to.

Python Code:

import requests
import os

base_url = ""
access_token = "Your_api_token"
sheet_id = "1234567"  # Replace with your sheet ID
attach_url = base_url + '/sheets/{sheet_id}/rows/{row_id}


def upload_attachment(row_id, file_path):
    url = attach_url.format(sheet_id=sheet_id,row_id=row_id)
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Disposition": f"attachment; filename=\'os.path.basename(file_path)\'"

    files ={'file': open(file_path,'rb')}

    response=, headers=headers, files=files)

    if response.status_code == 200:
        print("Attachment uploaded successfully to row", row_id)
        print(f"Failed to upload attachment to row", row_id)


  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭

    I don't have time to dig into this and provide a detailed answer. I will suggest that instead of python's requests module, you should use the Smartsheet Python SDK, it takes care of many issues for you, including dealing with rate-limits and retries.

    There are times you may need to go beyond the SDK, and directly use requests , but I have found this to be rare

  • rye
    edited 03/18/24

    Hi @Lee Joramo

    I have tried using Smartsheet Python SDK as well . But I could see same that code is executed without any output.

    Python Code:

    import os
    from smartsheet import Smartsheet
    from smartsheet.models import Sheet, Row, Column, Cell
    access_token = 'Your_Token_Access'
    # Initialize smartsheet
    ss_client= Smartsheet(access_token)
    sheet_id = 'Your_Sheet_ID'
    column_id = 'Your Column ID'
          'File path 1':'Row_1',
          'File path 2':'Row_2'
    #Function to upload files to smartsheet
    def upload_files_to_smartsheet(files_and_rows, sheet_id, column_id):
        #Open the sheet
        sheet = ss_client.sheets.get_sheet(sheet_id)
       #Iterate over files and rows
        for file_path, row_id in files_and_rows:
            #Create a new row
            new_row = Row()
            new_row.cells.append(Cell(column_id, value = os.path.basename(file_path)))
            #Attach the file to row
            response = ss_client.Attachments.attach_file_to_row(sheet_id, row_id,file_path,new_row.cells[0])
            if response and response.message:
                print(f"File {file_path} uploaded successfully to row {row_id}")
                print(f"Failed to upload files")
  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭

    @rye I will try to give this a review later today. However, I will note that you included what appears to be a real API token. You will want to reset that ASAP. (We have all done this sort of thing.)