What is the proper syntax for using "Invoke-WebRequest" command with api.smartsheet.com?
Hello All,
I'm using Windows Powershell to access and download smartsheet data via https://api.smartsheet.com. When using the curl command from dos prompt, the following works fine: curl https://api.smartsheet.com/2.0/sheets/{7517664106047364} -H "Authorization: Bearer *********************" -H "Accept: application/vnd.ms-excel" -o TestDB.xlsx
However, I would like to use Windows Powershell as my scripting utility. While in Powershell, &curl.exe is not working and the "Invoke-WebRequest" command is also not working. But I'm not sure if the smartsheet api is developed to handle the "Invoke-WebRequest" command switches. Could anyone provide some insight as to what I'm not doing correctly. very new to smartsheet api.
Thanks!
Willie R
Answers
-
I'm not familiar with Powershell, however I found a few other discussion threads in Stack Overflow that may help you:
- Powershell Invoke-Restmethod aborted due to SSL/TLS Secure Channel (Smartsheets API)
- Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel
- Github PSSmartsheet
Based on the first linked thread, it sounds like one solution could be to tell Powershell to use TLS 1.2 when invoked.
Cheers,
Genevieve
Join us at Smartsheet ENGAGE 2024 🎉
October 8 - 10, Seattle, WA | Register now -
What error are you getting when using the Invoke-WebRequest command? I use the Invoke-RestMethod command, but both should work.
Brady
-
"Windows Powershell" does not include some of the advanced command switches unless you manually install "Powershell 7".
To answer your question directly (Windows Powershell 5):
Invoke-WebRequest -Uri "https://api.smartsheet.com/2.0/sheets/7517664106047364" -Headers @{Authorization = "Bearer ************"; Accept = "application/vnd.ms-excel"} -Method Get -UseBasicParsing -OutFile TestDB.xlsx
as you can see it's a monster one-liner... so split over a couple lines, the same thing could be like:
$Sheet = 7517664106047364
$URL = "https://api.smartsheet.com/2.0/sheets"
$Headers = @{
Authorization = "Bearer ************"
Accept = "application/vnd.ms-excel"
}
$MyFile = "TestDB.xlsx"
Invoke-WebRequest -Uri "$URL/$Sheet" -Method Get -Headers $Headers -OutFile $MyFile
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 62.8K Get Help
- 376 Global Discussions
- 207 Industry Talk
- 440 Announcements
- 4.5K Ideas & Feature Requests
- 139 Brandfolder
- 129 Just for fun
- 130 Community Job Board
- 449 Show & Tell
- 30 Member Spotlight
- 1 SmartStories
- 284 Events
- 33 Webinars
- 7.3K Forum Archives