How to Run Power Automate Flow using API in C#

In this post, we will trigger the Microsoft Flow using an API in C#. This approach is useful when you want to reduce your application code and let Power Automate take care of most of the things.

This demo is part of E-commerce bot for email authentication feature.


  1. Visual Studio
  2. Microsoft Flow Account
  3. Run Power Automate flow from the Postman using API

Visual Studio link is available in the Downloads page.


Create a Console Project in Visual Studio

Make sure you have completed requirement 3. There, we have created a flow to send an email on the HTTP request. We have also got the HTTP POST URL from there which is required for us to call the API.

Create a new Console Application project and name it TriggerMSFlow.

Choose the target framework .NET Core 3.1 (Long-term support).

Add the following code the Program.cs file.

using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace TriggerMSFlow
    public class Program
        static async Task Main(string[] args)
            Program program = new Program();
            await program.SendEmailForCodeVerificationAsync(174582, "", "JD Bots", "<your Power Automate POST URI>");

        public async Task SendEmailForCodeVerificationAsync(int verificationCode, string toAddress, string username, string uri)
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(uri);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress);
                var body = $"{{\"emailAddress\": \"{toAddress}\",\"emailSubject\":\"[NaamiChocos] Email Verification Code\",\"userName\":\"{username}\",\"OTP\":\"{verificationCode}\"}}";
                var content = new StringContent(body, Encoding.UTF8, "application/json");
                request.Content = content;
                var response = await MakeRequestAsync(request, client);

            catch (Exception e)
                throw new Exception();

        public async Task<string> MakeRequestAsync(HttpRequestMessage getRequest, HttpClient client)
            var response = await client.SendAsync(getRequest).ConfigureAwait(false);
            var responseString = string.Empty;
                responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
            catch (HttpRequestException)
                // empty responseString

            return responseString;

    public class AuthenticationModel
        public string status { get; set; }
        public string message { get; set; }

Make sure to install and import necessary NuGet packages. Replace your Power Automate POST URI in the Main. Below is the output on the console window.

Output from Email:

Output from Power Automate:

You can open up the individual steps to see their output.

Thank you All!!! Hope you find this useful.

Leave a Reply

Up ↑