Here is the fix.
$Payload = $WebhookData | ConvertFrom-Json was not needed.
I took this from the Microsoft example. So, I assumed this working.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure Automation Powershell 5.1 Runbook unable to get json payload.
This code works to get the parameters in 7.2 but I am using the exhangeonlinemanagement module which is having other issues in runbooks with 7.2. I need to get this working asap. So, I wanted to 5.1 for now.
What am I doing wrong?
Payload
[{
"Alias": "jack",
"User" : "john"
}]
All I need to do is get the parameters from the payload, but I keep getting this error:
ConvertFrom-Json : Invalid JSON primitive: . At line:11 char:31 + $Payload = $WebhookData | ConvertFrom-Json + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
- FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
This is the code in my RunBook
param
(
[Parameter (Mandatory = $false)]
[object] $WebhookData
)
if ($WebhookData) {
Write-Output $WebhookData.RequestHeader
$Payload = $WebhookData | ConvertFrom-Json
if ($Payload.RequestBody) {
$aliases = (ConvertFrom-Json $Payload.RequestBody)
foreach ($x in $aliases)
{
$alias = $x.Alias
$user = $x.User
Write-Output "Alias: $alias"
Write-Output "User: $user"
}
}
else {
Write-Output "Request Error"
}
} else
{
Write-Output "Missing information";
exit;
}
Here is the fix.
$Payload = $WebhookData | ConvertFrom-Json was not needed.
I took this from the Microsoft example. So, I assumed this working.