Connect to custom on-premises APIs using data gateway

At Ignite 2017, we announced the ability for Flow and PowerApps users to be able to use the on-premises data gateway to connect to APIs hosted within your internal network. This is a very exciting feature as it will allow you to extend the capabilities of the Flow and PowerApps to suit your very specific needs. In this blog post, I will show you how you can create a simple ASP.NET based REST API, host it on your local machine and connect to it via Flow and PowerApps.

Part 1. Create your Visual Studio Project and Web API

  • Start off by create a ASP.NET Web Application, by navigating to File > New Project > Web > ASP.NET Web Application

  • On the next screen, select Web API and uncheck the “Host in the cloud” check box.
  • To keep things simple, click on “Change Authentication” and select “No authentication”. You can choose to protect your API – using Basic or Windows authentication, if you so desire.

  • After, clicking “OK”, Visual Studio will take a few moments to create your boiler plate Web API and you should see the following screen on successful creation of the application.

  • Navigate to the Controllers Folder in the Solution Explorer and ensure that you have the values controller to exercise through a web request tool like Fiddler or Postman.

  • Deploy your solution by clicking on the Play button in the toolbar.

  • The home page of your web API should open in a browser. The web API should now be running locally on IIS, make a note of the URL and Port that points to your web API

  • Using the Composer functionality in Fiddler, we can now exercise our API by making a GET call to http://localhost:1876/api/values/. If the request returns with a 200 OK response, you have successfully created and hosted a RESTful web API on your local machine.

  • Next, we need to make sure that we can access the Web API using the local machine’s IP address, which means that making a GET call to http://{YOUR_IP_ADDRESS}:{YOUR_PORT_NUmber}/api/values/ should return the same results. If you can’t get this to work, make sure IIS is configured correctly to allow calling your API using your machines IP address. This blog post goes in detail on how you can do just that, in case you are using IIS Express to host your API.

Part 2. Registering your on-premises Web API as a custom connector in Microsoft Flow or PowerApps

If you aren’t familiar with custom connector and required concepts, I highly recommend reading up on it before proceeding further. The section assumes that you’re familiar with custom connector concepts.

  • Start by navigating to the Microsoft Flow or the PowerApps web portal and click on the Gear menu > Custom Connector. Click + New Custom Connector and select from Create from blank. Next, give a name to your connector.

  • Fill out the general section, of the custom connector. The most important piece here are the base URL and the host. Make sure you set it up to use your IP and Port. Ensure that you also select the correct scheme, for this instance we should be using HTTP, as we haven't configured our API to use HTTPS.

  • As our API uses no authentication, we don’t need to change anything on the Security Tab.
  • Under the definition tab, we will go ahead and define the Get Values operation by importing a sample request and response.

  • Once everything is imported and validated, go ahead and create the connector. The connector will take a few minutes to be operational.

Part 3. Testing the Custom Connector via on-premises data gateway

  • You will need to install an on-premise data gateway on a machine inside your network. You can download the latest version of the on-premises data gateway from here. Once setup correctly, you should see a successful status on your local installation of the gateway.

  • After installing the gateway, create a connection for testing the connector. Make sure you choose the gateway we just installed to connect through to our on-premises web API.

  • Finally, test the custom connector by actually making a request though the test custom connector UI. If you see a 200 OK response come back, you have successfully managed to accomplish exactly what we had initially set out do.

If you have any questions, suggestions or feedback about the on-premises custom connector capability, please feel free to post below in the comments, in our community, or reach out on Twitter.