'Calling Azure Automation runbook from ADF Webhook activity - Fails with "Cannot bind argument to parameter 'InputObject' because it is null."

we are trying to call an Azure Automation Runbook from a Webhook activity in a Azure Data Factory pipeline.

We work from the instructions provided in this blogpost: https://medium.com/hitachisolutions-braintrust/3-steps-to-run-powershell-in-azure-data-factory-e7c73d38e548.

There are two components involved:

  1. An Azure Automation Runbook, containing a PowerShell script
  2. An ADF pipeline webhook activity, calling the Automation Runbook

The intent is to read an attribute (RequestBody) contained within the input parameter (WebhookData) of the PS script which represents a json formatted string.

For sake of clarity I have stripped away as much code as possible (the actual script contains many more lines). For instance, I have removed any reference to the Callback etc... as (at this point) this is not part of the issue we are facing.

In addition I describe 2 consecutive versions of the Automation Runbook in order to demonstrate how we tried to resolve the error so far.

Automation runbook (initial version)

PowerShell code for the runbook:

param (
[Parameter (Mandatory = $false)]
[object] $WebHookData
)

$Parameters = (ConvertTo-Json -InputObject $WebhookData.RequestBody) // This line fails

Webhook activity

json definition for the webhook activity that calls the Automation runbook:

{
"name": "Automation Runbook Test",
"properties": {
    "description": "Performs a simple test to call a runbook from within ADF",
    "activities": [
        {
            "name": "WebHook1",
            "type": "WebHook",
            "dependsOn": [],
            "userProperties": [],
            "typeProperties": {
                "url": "https://xxxxxxxx-94be-4cb8-9ba7-b50d7de44a82.webhook.we.azure-automation.net/webhooks?token=xxxxxxxxxx6bjpZH36io1mhP%2b5k2yr%2bMcVvsYGjdZPE%3d",
                "method": "POST",
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": {
                    "ParmMsg": "I am completely operational, and all my circuits are functioning perfectly."
                },
                "timeout": "00:00:30"
            }
        }
    ],
    "folder": {
        "name": "Refresh Power BI"
    },
    "annotations": []
},
"type": "Microsoft.DataFactory/factories/pipelines"
}

Execution error

When executed the automation runbook fails with following error: Cannot bind argument to parameter 'InputObject' because it is null.

Automation runbook (2nd version)

In an attempt to understand what is going on we tried several things. We noticed that converting the WebhookData parameter to a PSCustomObject seemed to get us one step closer, but when we then try to move on we bump into the next issue. And this is where we are stuck at this point.

Here is the new version:

param (
[Parameter (Mandatory = $false)]
[object] $WebHookData
)

# Convert WebhookData parameter (json-formatted string) to an Automation.PSCustomObject object
$WebHookData = (ConvertFrom-Json -InputObject $WebhookData)
Write-Output "WebhookData.RequestBody"
Write-Output "-----------------------"
Write-Output $WebhookData.RequestBody

# Get all parameters from body 
# (passed from Data Factory Web Activity)
$Parameters = (ConvertFrom-Json -InputObject $WebhookData.RequestBody) // This line fails

Write-Output "Parameters"
Write-Output "----------"
Write-Output $Parameters

Output & error (from 2nd version)

The Write-Output Of the $WebhookData.RequestBody shows that escape characters (\r\n) were added to the RequestBody attribute, compared to the original json that was entered in the ADF webhook activity settings (see above):

WebhookData.RequestBody
-----------------------
{\r\n "ParmMsg": "I am completely operational, and all my circuits are functioning perfectly.",\r\n "callBackUri": "https://dpwesteurope.svc.datafactory.azure.com/dataplane/workflow/callback/....

The script now fails with
Conversion from JSON failed with error: Invalid property identifier | character: . Path '', line 1, position 1.

When the escape characters are (manually) removed the script runs fine. However, these escape characters are put there by the ADF Webhook activity and there seems to be no way to control this. It shouldn't be changed there neither I think. Instead, the Automation runbook script should probably be altered such that it recognizes the RequestBody attribute (of the outer WebhookData object) as a valid json which it can convert into a PSCustomObject. As illustrated, our script clearly fails doing so at this point.

Any suggestions are very welcome.

Thanks!

Update since original post

I changed the runtime version of the runbooks from 7.1 (preview) to 5.1. With the 5.1 version the script seems to run correctly. So, is the 7.1 version the cause, or am I missing something else here?



Solution 1:[1]

Turns out that there is currently a known issue with Powershell 7.1 (preview):

When you start PowerShell 7 runbook using the webhook, it auto-converts the webhook input parameter to an invalid JSON.

source: https://docs.microsoft.com/en-us/azure/automation/automation-runbook-types#known-issues---71-preview

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kurt Petteloot