Hi Team
I want to attach an excel file in api in Invoke Web Service Action Please provide the solution.
@Sanket1
Please follow the below powershell script to achieve the same.
Code:
@@copilotGeneratedAction: 'False'
Scripting.RunPowershellScript.RunPowershellScript Script: $'''# Web API endpoint URL
$apiUrl = \"https://localhost:44387/api/values/pivottable\"
# Input file path
$inputFilePath = \"C:\\Users\\deenu\\Downloads\\Excel A.xlsx\"
# Output file path to save Excel
$outputFilePath = \"C:\\Users\\deenu\\Downloads\\newoutputexcel.xlsx\"
try {
# Create a WebClient object
$webClient = New-Object System.Net.WebClient
# Create a new FormData instance
$formData = New-Object System.Collections.Specialized.NameValueCollection
$formData.Add(\"file\", $inputFilePath)
# Upload the file using multipart/form-data
$responseBytes = $webClient.UploadFile($apiUrl, \"POST\", $inputFilePath)
# Save the response content as byte array to output Excel file
[System.IO.File]::WriteAllBytes($outputFilePath, $responseBytes)
Write-Output \"Excel file saved successfully.\"
}
catch {
Write-Output \"An error occurred: $_\"
}
''' ScriptOutput=> PowershellOutput
Thanks,
Deenuji Loganathan 👩‍💻
Automation Evangelist 🤖
Follow me on LinkedIn 👥
-------------------------------------------------------------------------------------------------------------
If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏
Tomac
986
Moderator
stampcoin
699
Super User 2025 Season 2
Riyaz_riz11
577
Super User 2025 Season 2