How to webhook in Azure function app in PowerShell

Tanmoy Das 801 Reputation points
2021-04-26T09:52:16.52+00:00

Hi,

Can I please get some help on azure function app using PowerShell.

How to use Webhook to get input in Azure powershell function app

using namespace System.Net

param($Request, $TriggerMetadata)

Write-Host "PowerShell HTTP trigger function processed a request."

$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}

$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."

if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body

})

Please suggest

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,327 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pramod Valavala 20,591 Reputation points Microsoft Employee
    2021-04-27T07:50:14.87+00:00

    anonymous user the sample function generated highlights how you can access the query parameters and the body of the request (via the $Request variable). If you are dealing with JSON payloads, it is parsed for you.

    You can refer the other properties of the both the request and response objects in the docs.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. OliverR-82 1 Reputation point
    2021-08-23T13:44:29.907+00:00

    Hi, I am having difficulties getting the Webhook action to work with an Azure (Powershell) function. More specifically, I don't know how to respond back to the Power Automate flow. I am trying to get the sample script to work with the added last line to respond to Power Automate. Is this (Invoke-RestMethod) the right way to do it?

    using namespace System.Net  
    # Input bindings are passed in via param block.  
    param($Request, $TriggerMetadata)  
      
    # Write to the Azure Functions log stream.  
    Write-Host "PowerShell HTTP trigger function processed a request."  
      
    # Interact with query parameters or the body of the request.  
    $targetSite = $Request.Query.TargetSite  
    $callbackUrl = $Request.Query.callbackURL  
      
    # Write out the queue message and insertion time to the information log.  
    Write-Host "Received provisioning request for site: $targetSite"  
    Write-Host "Received callback url: $callbackUrl"  
      
    $status = [HttpStatusCode]::OK  
    #$body = "Provisioning to $targetSite succeeded"  
      
    $Result = Invoke-RestMethod -Uri $callbackUrl -Method Post -body $status  
    

    The above code is failing with the following error message:

    The request must be authenticated only by Shared Access scheme

    This is what the Power Automate flow looks like so far, just for testing purposes:
    125590-screenshot-2021-08-23-154704.png

    I am not a developer. I'm an IT professional proficient with the Power Platform but not in writing functions. Any help with this would be greatly appreciated.


  2. Magnus Jakobsen 6 Reputation points
    2022-09-16T06:37:23.343+00:00

    @OliverR-82
    Did you ever solve your issue? I'm in the exact same position now.

    Regards,
    Magnus

    0 comments No comments