Call Azure Function App from Microsoft Flow (Part I)

We need to update SharePoint list items based on data that is returned from a custom web service. What makes this problem more complicated (and much more interesting) is that we need to process the web service results in an Azure Function App before they can be consumed by the Flow.

In Part II, we create a custom data connector that will allow us to get data from the Azure Function in our Flow.

In Part III, we will create a Flow that uses data returned from the Azure Function (via our custom data connector).

First, we create an Azure Function.

Next, we create a method that calls the custom third-party web service.

private static async Task<HttpResponseMessage> CallWebService(string email = null, string city = null, string lastName = null)
            using (var client = new HttpClient())
                string url = 'https://yourcustomwebservic' + email;
                 var request = new HttpRequestMessage(HttpMethod.Get, url);
                    byte[] byteArray = Encoding.ASCII.GetBytes("yourbasicauthaccount:yourbasicauthpassword");

                   client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(byteArray));

                    return await client.SendAsync(request);
                    HttpResponseMessage msg = new HttpResponseMessage();
                    return msg;

This begs the question: why do this in the Azure Function rather than directly from the Flow? First, it simplifies the auth process. But second (more importantly) it allows us to do some processing in the Azure Function. A ‘switch/case’ method in C# will run much faster than if we were to handle the same business logic in the Flow.

For example, here is some business logic that we can handle in the Azure Function:

private static string MapCodeToStatus(string code)
            string returnVal = "Unknown Mapping";
            switch (code)
                case "010":
                case "015":
                case "019":
                case "020":
                case "030":
                case "050":
                case "100":
                    returnVal = "02-Candidate Applied";
                case "059":
                case "060":
                    returnVal = "03-Interview Candidate";
                case "069":
                case "070":
                case "075":
                case "078":
                    returnVal = "04-Candidate Offered Job";
                case "071":
                case "076":
                case "080":
                case "090":
                    returnVal = "05-Candidate Accepted Offer";
                case "035":
                case "055":
                case "072":
                case "077":
                case "110":
                case "112":
                case "115":
                case "120":
                case "130":
                case "140":
                    returnVal = "07-Cancelled";
                    returnVal = "Unknown Mapping";

            return returnVal;

Next we create a custom data connector to wrap this web service and make it available to our Flow, which I will cover in Part II of this series.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close