Call Custom API in PowerApps
Andreas Aschauer
Senior Technology Specialist - Agentic Platforms & Low Code Development
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
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.