Hi,
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 = "https://api.smartsheet.com/2.0"
access_token = "Your_api_token"
sheet_id = "1234567" # Replace with your sheet ID
attach_url = base_url + '/sheets/{sheet_id}/rows/{row_id}
row_attachments={'file_path':'row_id',
'file_path_1':'row_id_1',
'file_path_2':'row_id_2',
.......
}
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-Type":"application/octet-stream",
"Content-Disposition": f"attachment; filename=\'os.path.basename(file_path)\'"
}
files ={'file': open(file_path,'rb')}
response= requests.post(url, headers=headers, files=files)
if response.status_code == 200:
print("Attachment uploaded successfully to row", row_id)
else:
print(f"Failed to upload attachment to row", row_id)
print(response.text)