Call REST API From Microsoft FLOW

In this article, we will see how to make the REST Web API authenticated and how to consume it from Microsoft Flow.

Introduction

 
You might have come across a scenario where you need to perform a CRUD operation on your on-premise data from Office 365 apps. To read on-premise data you can easily use On-premise gateway but if you need to write the data then you need to create Web API/ Web service to do so. API can be hosted on one of the servers in on-premise networsk, exposed outside the firewall, and authenticated. This API can be triggered by cloud applications easily.
 
Details
 
We will see two parts in this article, first is what kind of authentication you need to enable on IIS for your API; and the second is how we can call such an API from Microsoft FLOW.
 

Make API authenticated

 
If you want to check out how to create a REST web API project, then check out this article.
 
From IIS, where your API is hosted make sure that you have enabled Basic and Windows authentication for your application as shown below
 
Go to IIS >> Expand/Select IIS site (where API is hosted) >> Click on Authentication Icon >> Check that basic and Windows authentication are enabled
 
Call REST API From Microsoft FLOW
 

Call authenticated API from FLOW

 
Let's see how we call such authenticated API from Microsoft FLOW.
 
In FLOW, there is an action called “HTTP” using this action we can call REST API and get the response as needed.
 
Call REST API From Microsoft FLOW
 
Choose HTTP Action in your FLOW, and the  below screen will appear for the configurations.
 
Call REST API From Microsoft FLOW
 
As you can see you need to provide all the values for Method, URI – API endpoint URL, headers (if any), body (data to be sent to API methods can be string or JSON), and authentication parameter.
 
Choose the Method – GET, PUT, POST, PATCH, DELETE.
 
Call REST API From Microsoft FLOW
 
Enter input parameters to be sent to the API method in body, this can be string or JSON data.
 
Call REST API From Microsoft FLOW
 
You can choose the authentication option >> depending upon what kind of authentications are supported by your API. If your API is hosted in Azure web app then you can choose Active Directory OAuth; if it's an on-premise hosted API then choose basic authentication.
 
Call REST API From Microsoft FLOW
 
In our scenario we will choose basic authentication >> enter user name and password of the user who has permission on the API site. You need to enter the username with the domain name. In some cases, the user might be a local user on the server, so the full name will be ComuterName\UserName. If it's AD user, the username will be Domain\UserName. Keep this in mind.
 
Call REST API From Microsoft FLOW
 
We're done, so we are good to test now. Save the FLOW and click on Test. If you have provided all the details correctly, if your API is accessible from outside the firewall of your organization, and if the provided credentials are correct, then your FLOW will run successfully as shown below:
 
Call REST API From Microsoft FLOW
 
If you are facing any issues – or getting an unauthorized error, then you can test the API authentication from SoapUI first. In SoapUI you can choose the authentication and provide the details. There is an Auth option at the bottom in request window >> click on it
 
Call REST API From Microsoft FLOW
 
Select the method as NTLM >> provide username domain and password and run the request.
 
Call REST API From Microsoft FLOW
 
That’s it for this article. I hope this helps.