-1

I am trying to pull information from the Smartsheets API- I can successfully get values of the cells and column headings. I am not using the SDK for the site, as it was not working properly. There are attachments on some of the rows and I would like to download them and save them to my computer. 'attachments' looks like it should be a key value after I access the 'rows' key, but an error occurs saying that 'attachments' is not a key. How do I access an attachment on a row without using the SDK?

for d in range(n_rows):
    print(data['rows'][d]['attachments']
John Gordon
  • 29,573
  • 7
  • 33
  • 58
reiem87
  • 1
  • 2
  • What problem did you have with the Smartsheet Python SDK? I use it all the time and have never run into any issues. FWIW, using the SDK will save you a lot of time and effort compared to not doing so. – Kim Brandl Mar 16 '23 at 04:51
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 16 '23 at 07:11
  • What is `data`? What is `n_rows`? You've given us almost zero details about this code. We can't possibly help... – John Gordon Mar 19 '23 at 23:27
  • Junichiro Miyazaki- Thank you, that definitely helps some. / – reiem87 Mar 20 '23 at 13:54
  • Kim- I did try to use it, but for some reason when I downloaded all the files (at least I believe I did) from github, it kept telling me I did not have the all the modules. I went back to check and I am pretty sure I downloaded all the required files. I would love to use it instead of manually doing this. – reiem87 Mar 20 '23 at 13:56

1 Answers1

0

I agree with Kim that "using the SDK will save you a lot of time."

As for your question, you may not have specified to include attachments.

params = {
    'include': **'attachments'**
}

response = requests.get(f'https://api.smartsheet.com/2.0/sheets/{sheetId}}', params=params, headers=headers)

Or if you use SDK,

sheet = smartsheet_client.Sheets.get_sheet(
    sheet_id,
    include = **'attachments'**)

Or you could use the list attachments method.

response=requests.get(f'https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments', headers=headers)

Either way, to download an attachment, you need to get an "attachmentId."

Then, with "attachmentId," use the get attachment method to "Fetches a temporary URL that allows you to download an attachment. "

response = requests.get(f'https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments/{attachmentId}', headers=headers)

Or if you use SDK,

attachment = smartsheet_client.Attachments.get_attachment(
  9283173393803140,  # sheet_id
  4583173393803140,  # attachment_id 
)          
WyattBlue
  • 591
  • 1
  • 5
  • 21