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
Need more help? 👀 | Help and Learning Center
こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 | Global Discussions
-
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
- 64.2K Get Help
- 419 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 142 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives