I've written a PowerShell script which downloads a file from a URL to the local PC then uploads that file to a SharePoint Online library. Running the script locally works but when I try getting it to run from a runbook triggered by Flows/Power Automate I get the error: Action HTTP failed; Input value wasn't JSON object. This flow is manually triggered and was working before I put the Create Job step in.
Screenshots and PowerShell script below, any help is greatly appreciated.
![Screenshot1]()
Set Variable: actions('HTTP').outputs.headers.Location
Compose: concat('https://api.sendgrid.com/v3/messages/download/',substring(variables('redirect'),63,36)) ![Screenshot2]()
Compose 2: replace(replace(body('HTTP_2'),'{"presigned_url":"',''),'"}','') Compose 3: replace(outputs('Compose_2'),'%2F','/') ![Screenshot 3]()
PowerShell: Function Download-File() { param (
[Parameter(Mandatory=$true)] [string] $url, [Parameter(Mandatory=$false)] [SecureString] $secPW
)
$fileOut = "C:\temp\testDownload.csv" try { #Get download file and write to C:\temp\testDownload.csv Invoke-WebRequest -Uri $url -OutFile "C:\temp\testDownload.csv"
Write-host "Download complete"
#Set up Credentials $user = "me@mysharepointsite.com" $PW = "P@ssW0rd!!" $secPW = $PW | ConvertTo-SecureString -AsPlainText -Force
$site = "https://mysharepointsite.sharepoint.com/sites/Test/" #Write credentials to PSCredential object $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$secPw #Connect to SharePoint Online Connect-PnPOnline -Url $site -Credentials $creds
#Upload File Write-Host "Upload Started"
Add-PnPFile -Folder "test123" -Path $fileOut
Write-Host "Upload Completed"
} catch { write-host -f Red "Download failed: " $_.Exception.Message }
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;