In a time where technology is very fast changing, I see some of the Organizations that still rely on so-called legacy systems or probably still depend on systems that just run on their network (on-premise). So, today, we will learn how to call on-premise WebAPI from Canvas Apps.
Create WebAPI
First, we will try to create the API that will be hosted on our local machine.
If you did not yet enable the IIS, you need to check all of this on your machine:
Create ASP.NET Web Application (.NET Framework):
Set the Project name as “LocalWebApi”, and set the Location to your desired folder. Last, change the Framework to “.NET Framework 4.8“. Once you click Create, set the template to “Empty“. For Authentication, you can set it to “None” as we want the demonstration to be simple (and also for security purposes, we pass it to the Power Automate instead 😊). Set “Web API” for the “Add folders & core references”. Untick the “Configure for HTTPS” and hit Create button.
Create a new Controller with the code below:
using System.Web.Http;
namespace LocalWebApi.Controllers
{
public class GreetingController : ApiController
{
// GET: Greeting
public IHttpActionResult Get()
{
return Ok("Hello from LocalWebApi..");
}
}
}
If when you try this you have several generated files that causing errors, just delete those files (BundleConfig.cs, FilterConfig.cs, and RouteConfig.cs) as we don’t need them.
You can try to debug it to verify if the API working fine > publish the project into the folder > then you can go to the IIS folder and create a folder + publish files into this folder:
Once you finished the above step, go to your IIS Manager > refresh > right-click on the folder your created > Convert to Application:
With this, you are successfully hosting the API on your machine. We can verify this using the Postman/your own browser. You just need to go to “http://localhost/powerautomate/api/greeting”:
Update/Install the Latest Version of Power Automate
Because we want to use Desktop Flow, we need to ensure that we are using the latest version of Power Automate. You can check this link to get the latest installer and the tutorial to add a machine that will be used to trigger the flow later.
Once you install it, open the Power Automate: machine runtime > go to Machine settings to make sure your computer is listed there (you also need to change the default environment for the flow to the environment that you will test/use):
Create the Flow
Open your Power Automate application on your machine (if you did not yet install it, click this link) > log in using the credentials that you want + select the Environment that you want to use:
Create New Flow > Name it as what you want (in my demo, I named it “Execute Greeting API”) > Go to the HTTP section and select “Invoke web service” > In the action, set the parameter like the URL, the Method, etc:
Next, create Output (to save the result from the API) response for the Flow:
Last, use the Set Variable action and assign the WebServiceResponse to the Message output variable:
Once it is done, we can run the Flow and verify the result:
Click Save and the flow is ready to be used. For our demonstration, I created the below Canvas Apps:
Regarding the “Canvas App Greeting” flow, you need to create a new Flow that will use “Run a flow built with Power Automate for Desktop“. You need to fill in the below information based on your machine setting:
Then the next part is just how we execute the Power Automate Desktop Flow and return the message:
Once it is done, you can run the Canvas App, and here is the result:
As you can see in the result above. It takes around 21 seconds for that operation. Kinda slow, but the purpose of it is about a “low code” way where you actually can call legacy API in your on-premise system from the cloud (if your organization has lots of restrictions).
Happy CRM-ing!