Call Azure Function From Power Automate

This Azure tutorial will discuss calling an Azure Function from Power Automate (MS Flow). We will also discuss the Call Azure Function From Power Automate (MS Flow) With OAuth.

Call Azure Function From Power Automate

We will discuss How to Call An Azure Function From Power Automate (Microsoft Flow). Before starting the development, we should know the Prerequisites needed for this development activity.

Prerequisites

  • An Azure Subscription or Azure Account. If you don’t have an Azure Account, Create an Azure Free Account now.
  • Power Automate (MS Flow) license (O365 E3 Developer)

How to call Azure Function from Power Automate

So, as part of the development activity, we will first create an Azure Function app in the Azure Portal and then create an HTTP trigger for Azure Function. Finally, we will change the Power Automate(MS Flow). Now, let’s create the Azure Function App

Create An Azure Function App

1. Log in to the Azure Portal (https://portal.azure.com/)

2. Once you log in to the Azure Portal, Search for the Function App in the Azure Portal and click on the search result

call azure function from power automate

3. On the Azure Function App page, click on the + Add button to create a new Azure Function App.

4. The next step is to provide the below Details On the Create Function App Page,

  • Subscription: Choose the Correct Azure Subscription that you want to use here.
  • Resource Group: Choose your existing Resource Group, or you can create a new one by clicking on the Create new link if you don’t have any existing Resource group.
  • Function App name: You must provide a unique name for the Azure Function App of your choice.
  • Publish: Select the Code option here.
  • Runtime Stack: Make sure to choose the .Net Core option here.
  • Version: Choose the latest version of .Net Core here.
  • Region: Provide the Region for your Azure Resource.

Finally, Click on the Review + Create button.

power automate call azure function

Now, all the information you have entered will be validated, and if all is okay, you can see the Create button is enabled on the next window. Finally, click on the Create button to create the Azure Function app.

Your deployment has been completed successfully. Now, click the Go To Resource button to navigate to the Azure Function you created.

Call Azure Function From Power Automate (MS Flow)

The next step is to create the Azure Function. We will create an HTTP-triggered Azure Function here. To create the HTTP-triggered Azure Function, click on the Functions option from the left side of the Azure Function App page and then click on the + Add button to create the Azure Function.

How to Call Azure Function From Power Automate (MS Flow)

Now you need to choose the Development environment as Develop in portal and then choose the template option as HTTP trigger

how to call azure function from power automate

Now, provide a unique name for your Azure Function, choose Function as the Authorization level, and click the Add button to create it.

How to Call Azure Function From Power Automate or MS Flow

Now, you can see below that our Azure Function was created successfully. Click on the Code + Test link from the left side navigation on the Function page as highlighted below,

How to Call Azure Function From Power Automate or Microsoft Flow

You can able to see the run.csx file code as below

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    string responseMessage = string.IsNullOrEmpty(name)
        ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
}