Call Azure Function From Power Automate

calling azure function from power automate ms flow

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,

  • SubscriptionChoose 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);
}

Now click on the Test/Run button from the top to test if the function is working fine or not. Choose the HTTP method, provide the Body in JSON format in the Input Window, and click the Run button to test the Azure Function.

How to Call Azure Function From MS Flow

We got the response code as 200 OK and the expected HTTP response content, as highlighted below.

power automate azure function

Now click on the Get function URL button and then click on the Copy button as highlighted below to copy the complete Azure Function URL

trigger azure function from power automate

The Function URL should look like below

https://mymsflowazfn.azurewebsites.net/api/MyHTTPTriggerFN?code=QpeBSTLGTO2ss7RwOMsLgjarO7Tm5bq05KGkXpDmJSxbtcluKXTw8w==

Copy this and keep it in a notepad, as we will use this Function URL later.

Now that our Azure Function part is done, Assuming you have the Complete Azure Function URL, We will move to the next step, i.e., Calling Azure Function From Power Automate (MS Flow)

Creating the Power Automate (Flow)

  1. The first step is to access the Power Automate or MS Flow. Go to https://flow.microsoft.com
  2. Once you log in, click on the My Flows link in the left menu and then click on the + New button in the top menu, as highlighted below.
power automate trigger azure function

3. Once you click the + New button, click on the + Instant-from blank link as highlighted below.

azure function power automate

4. Provide a name for the flow or power automate on the Build an Instant flow page. For “Choose how to trigger a flow, ” choose Manually trigger a flow. You can choose the other trigger option based on your requirements. But for the time being, let’s choose the first option.

Power Automate Call Azure Function

5. You can see the flow has been created with the manual trigger flow option.

call azure function from Power automate (flow)

6. Click on the ‘+ New Step’ step. From the Choose an action, search for HTTP and select HTTP under the All tab. Then click on HTTP Premium under the actions tab highlighted below.

call azure function from Power automate

7. It might ask you to start your Free trial based on your Flow plan. Then, It will add the HTTP action like below.

call azure function from Power automate(MS Flow)

8. the next step is to select the Method as Post and paste the complete URL appending the name parameter value you have copied in the above steps. The complete URL will look like below

https://mymsflowazfn.azurewebsites.net/api/MyHTTPTriggerFN?code=QpeBSTLGTO2ss7RwOMsLgjarO7Tm5bq05KGkXpDmJSxbtcluKXTw8w==&name=Raj

Choose the Authentication as None and click the Save button, as shown below.

azure function power automate

Test the Power Automate (Flow)

We have created the complete flow and saved the Power Automate or flow. The time to test the Power Automate (Flow) and check if it is working fine.

To test the Power Automate or Microsoft Flow, click the Test button next to the Flow checker button at the top right corner of the page.

how to call azure function

On the Test Flow, I was hoping you could select the I’ll perform the trigger action and then click on the Test button to check whether the Power Automate is working.

call azure function from power automate or ms flow

On the next screen, it will show you the Owner details and enable the Run Flow button. Click on the Run Flow button to run the Power Automate or Flow.

Now you can see below your flow run successfully started.

power automate call azure function

You can click on the Flow Runs Page link as highlighted above. You can see the run history of the Power Automate with details on the time when precisely the flow was executed and the status as Succeeded, as shown below.

call azure functions from Microsoft Flow

Now click on the history as highlighted above, and you can see your flow ran successfully message with the Flow structure. Check out the below screenshot for your reference. Now click on the HTTP action as highlighted below.

power automate azure function

As you can see in the screenshot below, we got the expected Status Code of 200 and the exact output message in the Body, i.e., ” Hello, Raj. ” This HTTP-triggered function was executed successfully. So we successfully called the Azure Function from the Power Automate or Microsoft Flow and got the expected Outcome.

Microsoft flow call azure function

So This is how to call Azure function power automate using the above steps.

Call Azure Function From Power Automate (MS Flow) With OAuth

So, As we discussed, call the Azure function from power automate (ms flow) with Authentication as none. But as security is very important, We will discuss how to Call Azure Function From Power Automate with OAuth.

Remember, we will use Active Directory (OAuth) here. To configure the OAuth here, we need a few stuffs, like

  • Client ID
  • Tenant
  • Secret

You might wonder where I will get my Azure Function App’s Client ID and Secret. So here are the steps to configure and get those values

Log in to the Azure Portal again and Navigate to your Azure Function App page again.

Click on the Authentication / Authorization link from the left navigation. Select the App Service Authentication as On. Choose “Log in with Azure Active Directory” for the option Action to take when the request is not authenticated

Then click on the Azure Active Directory (Not Configured) Option.

call azure function from power automate (ms flow) with oauth

Then Select the Management mode as Express. Now again, select the Management mode as Create New AD App and then Provide a name for the Create App. By default, it will show you the name of your Function App, but if you want to change the Create App name, you can change it, too. Then click on the OK button.

Trigger Azure Function From Microsoft Flow

Then, make sure to click on the Save button from the window below.

Trigger Azure Function From Power automate

The next step is to search for the Azure Active Directory in the Azure Portal and click on the Search result.

On the Azure Active Directory pane, click the App registrations link in the left navigation. Then, you will see the registration for your Azure Function App that you configured above. Click on that.

Trigger Azure Function From Power automate(MS Flow)

Client ID

On the Overview tab, you can see the Client ID, as highlighted below. You can copy this to a notepad and keep it, as we will use it in our MS Flow Configuration.

Trigger Azure Function From Power automate or MS Flow

Secret

Now, the next thing we need is the Secret value. Click on the Certificate & Secrets from the left navigation highlighted in the above screenshot.

Click on the + New Client secret under the Client secrets section to generate a client secret to access the Azure Function App.

Trigger Azure Function From Power automate or Flow

Select the Expires option based on your requirement on the Add a client secret window and then click the Add button.

How to Trigger Azure Function From Power automate or Microsoft Flow

Now you can see the secret ID that you have created just now. Copy that value by clicking the Copy button as highlighted and keep it in a notepad.

One important point to note down here is to copy the secret immediately or else it will get encrypted after a few minutes.

Trigger Azure Function From Power automate or Microsoft Flow

Now we have our Client ID and secret with us. Let’s configure the OAuth in the Microsoft Flow.

After the Step number 7 above, You need to configure the below options now

  • Authentication: Select the Active Directory OAuth
  • Authority: https://login.microsoftonline.com
  • Tenant: Mention your Tenant’s Name
  • Audience: Put the client ID that you have copied before.
  • Client ID: Put the client ID that you have copied before.
  • Credential Type: Select Secret as the Credential Type.
  • Secret: Enter the Secret that you have generated above and copy it.

Now Click on the Save button as highlighted below.

How to Trigger Azure Function From Power automate

Now, click on the Test button next to the Flow checker. Select I’ll perform the Test Flow trigger action, then click the Test button.

Click the Run Flow button on the next screen to run the Power Automate or Flow. Now you can see your flow runs successfully started.

You can click on the Flow Runs Page link. You can see the History with the Status as Succeeded. You can click on history. Then click on the HTTP action, and you can see the Expected OutPut below (Refer to the Test the Power Automate (Flow) section for the detailed step with screenshots ).

We got the expected output with the status code 200 ok and the expected Outcome message. The Authentication section contains the client ID, Secret, and all other details needed for the ActiveDirectoryOAuth configuration.

Steps to Trigger Azure Function from Power Automate
Steps to Trigger Azure Function from Microsoft Flow

So, this is how to call an Azure function from Power Automate (MS Flow) with no authentication and call an Azure function from Power Automate (MS Flow) with OAuth, i.e., ActiveDirectoryOAuth, by following the above steps.

You may also like following the below Articles

Wrapping Up

In this article, we discussed calling an Azure function from Power Automate (MS Flow) and an Azure function from Power Automate (MS Flow) with OAuth. I hope you have enjoyed this article !!!