Call Custom API in PowerApps

Call Custom API in PowerApps

How cool is that! You can now directly call Custom Dataverse APIS from PowerApps!

What are custom APIs?

Developers can code Plugins and directly push that coded logic to a Dataverse environment. That way complex composite logic can be safeguarded and deployed to be repeatedly used by makers. Details see here:

Those custom plugins can then easily be "wrapped" into a Custom API with custom parameters - see here

As soon as the custom API is created, Makers can now call the API directly from PowerApps formulas

No alt text provided for this image
Calling a Custom API from PowerApps

This way, complex business logic can be accessed easily by makers, hiding possible complexity and making more operations accessible to a large audience of Low Code Makers.

In the screenshot above, the PowerApps Maker directly calls the function onboardemployee which is implemented as simple C# plugin code. It creates a contact and a subsequent appointment entity for an onboarding meeting.

public class PluginOnboardEmployee : PluginBas
? ? {
? ? ? ? public PluginOnboardEmployee(string unsecureConfiguration, string secureConfiguration)
? ? ? ? ? ? : base(typeof(PluginOnboardEmployee))
? ? ? ? {
? ? ? ? ? 
? ? ? ? }

? ? ? ? // Employee onboarding: Creates a new contact and an onboarding appointment
? ? ? ? protected override void ExecuteDataversePlugin(ILocalPluginContext localPluginContext)
? ? ? ? {
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (localPluginContext == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? throw new ArgumentNullException(nameof(localPluginContext));


? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? var context = localPluginContext.PluginExecutionContext;
? ? ? ? ? ? ? ? var service = localPluginContext.PluginUserService;
? ? ? ? ? ? ? ? var firstname = context.InputParameters["emp_firstname"];
? ? ? ? ? ? ? ? var lastname = context.InputParameters["emp_lastname"];


? ? ? ? ? ? ? ? //Create contact
? ? ? ? ? ? ? ? var contact = new Entity("contact");
? ? ? ? ? ? ? ? contact["firstname"] = firstname;
? ? ? ? ? ? ? ? contact["lastname"] = lastname;
? ? ? ? ? ? ? ? var empId = service.Create(contact);


? ? ? ? ? ? ? ? //Create onboarding meeting


? ? ? ? ? ? ? ? var entAppointment = new Entity("appointment");
? ? ? ? ? ? ? ? entAppointment["subject"] = $"Onboarding checkin {firstname}";
? ? ? ? ? ? ? ? // Set the start and end times for the entAppointment 7 days fro now
? ? ? ? ? ? ? ? entAppointment["scheduledstart"] = DateTime.Now.AddDays(7).AddHours(1);
? ? ? ? ? ? ? ? entAppointment["scheduledend"] = DateTime.Now.AddDays(7).AddHours(2);
? ? ? ? ? ? ? ? // Set the related account for the entAppointment
? ? ? ? ? ? ? ? entAppointment["regardingobjectid"] = new EntityReference("contact", empId);
? ? ? ? ? ? ? ? var appointmentId = service.Create(entAppointment);


? ? ? ? ? ? }
? ? ? ? ? ? catch (System.Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? throw new InvalidPluginExecutionException("Error onboarding employee", ex);
? ? ? ? ? ? }
? ? ? ? }
? ? }e        

Easy as that! The code is started in VSCode with the PAC command pac plugin init and the resulting Assembly (DLL) is registered with pac plugin push or pac tool prt which opens the plugin registration tool.

要查看或添加评论,请登录

Andreas Aschauer的更多文章

  • Towards a fully automated document intake with Power Platform

    Towards a fully automated document intake with Power Platform

    The rise of Generative Artifical Intelligence and subsequent introduction of Large Language Models into Microsoft Power…

    2 条评论
  • Low Code ALM - Using Power Platform Pipelines with Azure Dev Ops and Git

    Low Code ALM - Using Power Platform Pipelines with Azure Dev Ops and Git

    Microsoft Power Platform makes it easy for makers and developers of all skill levels to create apps, automations, AI…

    5 条评论
  • Power Platform Pro | Custom Connectors - Part 1

    Power Platform Pro | Custom Connectors - Part 1

    The following is a condensed intro to Custom Connectors and various Integration Options using Power Platform and…

  • Power to the people!

    Power to the people!

    The need to innovate and create is greater then ever and of utmost importance for every organization to be able to…

  • Fast Forward >>

    Fast Forward >>

    The Microsoft Business Application Platform as an enabler of change This is the first article in a series of…

    1 条评论

社区洞察

其他会员也浏览了