How to call DataVerse actions/ custom api directly from Power Apps canvas apps

Hello everyone and welcome to my blog. In today’s blog I will demonstrate how to execute Dataverse actions directly from a canvas app.

Dataverse actions are great. You can write very complex business logic inside a custom API. Not only that, you can pass multiple input parameters in the request and return multiple response properties.

Unfortunately for a very long time, there was no direct way of invoking a custom action from Canvas app. To achieve that, we would usually end up with a Power Automate flow and from within the Power Automate flow we shall call the action.

But now with this experimental feature, you can call custom API’s directly from canvas apps. So let’s get started.

First and foremost, as I mentioned this is an experimental feature. We need to enable this feature from Settings of the app. Check for the below screenshot.

The next step is to create a custom API. I shall limit my discussion on custom API and save it for another blog. However below screenshots should serve the purpose.

Custom API screenshot.

Custom API Request Property

Custom API Response Property

It’s a very simple API with one input parameter and one output parameter.

Below is the sample code for custom action.

public class SamplePlugin : IPlugin
   {
      public void Execute(IServiceProvider serviceProvider)
      {
         IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
         IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
         IOrganizationService service = factory.CreateOrganizationService(context.UserId);

         string param1 = (string)context.InputParameters["param1"];

         Entity account = new Entity
         {
            LogicalName = "account"
         };
         account["name"] = param1;
         var accId = service.Create(account);


         context.OutputParameters["sampleapi_output"] = accId.ToString();



      }
   }

Very simple isn’t it? All I am doing is taking an input parameter, create an account and then return the id of the newly created account.

Alright, time for the big test. To invoke custom action, we need to make a connection to the Environment table of Dataverse.

And once added, the next step is to invoke the custom action. And below is the code to call a custom API/ action on click of button.

Please note : As of the time of writing the blog, API’s with only primitive return types like Integer/ String/ Boolean/Decimal/ Money etc. Complex response types like entity and entitycollection are not available in power apps.

Hope you liked this post. If this post has helped, you can buy me a coffee. Links on right pane.

For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

You will also like the below posts.

Debajit Dutta
Business Solutions MVP