如何将Azure Automation Runbook Webhook请求体传递至Logic Apps
Solution: Pass Webhook Request Body to Logic Apps from Azure Automation Runbook
Key Issue with Current Code
Your existing code uses a GET request to invoke Logic Apps, which doesn’t support sending a request body. To pass the full Webhook request content, you need to switch to a POST request and include the body in the request payload.
Modified Runbook Code
Here’s the updated PowerShell code that sends the complete Webhook request body to your Logic Apps HTTP trigger:
param ( [Parameter(Mandatory=$false)] [object] $WebhookData ) if ($WebhookData.RequestBody) { # Parse the Webhook request body to ensure valid JSON structure $parsedRequestBody = ConvertFrom-Json -InputObject $WebhookData.RequestBody # Convert parsed object back to JSON with sufficient depth for nested fields $jsonPayload = ConvertTo-Json $parsedRequestBody -Depth 10 # Logic Apps HTTP trigger URI (replace {signature_certificate} with actual valid signature) $logicappURI = "https://logicapp/api/test/triggers/manual/invoke?api-version=2022-05-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig={signature_certificate}" # Send POST request with the full request body payload $response = Invoke-WebRequest -Method POST ` -Uri $logicappURI ` -Body $jsonPayload ` -ContentType "application/json" Write-Output "Logic Apps invoked successfully. Response status: $($response.StatusCode)" } else { Write-Output "No Webhook request body received." }
Key Changes Explained
- POST Request Instead of GET:
GETrequests can’t carry a request body, soPOSTis used to send the full payload to Logic Apps. - JSON Payload Handling: Parsing and re-serializing the Webhook request body ensures valid JSON formatting, and
-Depth 10handles nested structures like theRequestHeaderobject. - Content-Type Header: Setting
application/jsontells Logic Apps to expect and parse JSON data natively.
Logic Apps Configuration
In your Logic Apps HTTP trigger, access the full request body using the expression triggerBody(). For specific fields:
- Get the Webhook name:
triggerBody()?['WebhookName'] - Parse the stringified RequestBody array:
json(triggerBody()?['RequestBody'])(since theRequestBodyfield in your example is a stringified array)
Notes
- Ensure your Logic Apps HTTP trigger allows
POSTrequests (enabled by default for manual triggers). - Adjust the
-Depthparameter inConvertTo-Jsonif your request body has deeper nested structures than shown. - Replace
{signature_certificate}in your Logic Apps URI with the actual valid signature from your Logic Apps endpoint.
内容的提问来源于stack exchange,提问作者Abdulquadir Shaikh
相关产品推荐
相关产品推荐

