The User Name and Password of your webapp's Publish Profile need to be provided in the Headers of Invoke-WebRequest for authentication.
You can get the username and password in the Publish Profile. You can download the publish profile from the Azure Web App. And refer userName and userPWD values in the publishProfile section.
$userName = "{userName}"
$password = "{Password}"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password)))
Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET -OutFile $filePath -ContentType "multipart/form-data"
You can also get the username and password via scripts, see below example:
$ResGroupName = ""
$WebAppName = ""
$LogFolder = ""
$WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET -OutFile $filePath -ContentType "multipart/form-data"