Introduction
Microsoft has introduced a new way to communicate to Common Data Model through Custom API, assisting developers to integrate and communicate to Common Data Model more easily and securely.
To date, when we needed to implement some logic of integration with Common Data Model to some cross-domain system we usually used to implement a long chain which included below,
- Action – It acted as a receiving point for data, and as well as a trigger point for logic
- Plugin – It acted as a processing unit for incoming data, where the actual logic was implemented
And this implementation has certain drawbacks,
- We cannot restrict an Action to a specific role, which means any user with any role can call the action, though we can restrict the execution of logic using certain other tricks
- Action can be used by any developer to register any plugin code, and which at times used to change the entire logic processing, no restriction of stages exposed to register the plugin
- No way to hide a Custom Action in Metadata Web Call
- And Creation of Custom Action needed a technical knowledge of the system, as it cannot be created through Solutions in Portal
Microsoft recently introduced this unique concept of Custom Action wherein all the above shortcomings were fulfilled.
Steps to create a Custom API
- Login to your PowerApps Portal which can be accessed over here.
- Select your desired environment as we will need to create a solution in there
- Create a solution with a suitable name
![]()
And the First step is to create a CUSTOM API
|
Allowed Values
|
Explanation
|
Binding Type
|
Global: Entity: Entity Collection
|
Usually, we select as Global, as we do not want it to be associate with a specific entity or collection
|
Bound Entity Logical Name
|
|
If we have selected the entity, then we must pass a schema name of the entity
|
Is Function
|
Yes: NO
|
We are setting it as NO as we will be calling it through a custom API
|
Is Private
|
Yes: NO
|
It helps to hide the Custom API from been exposed in Metadata
|
Allowed Custom Processing Step Type
|
Sync: Async
|
|
Execute Privilege Name
|
Schema name of security role
|
It helps to restrict calling of Custom API only through specific roles
|
Post creation of Custom API, need to create desired set of
- Custom Request Parameters
Request Parameters is the value that will be passed to Custom API while been called through any source. It enables us to pass custom values which will be processed by our logic
![]()
- Custom Response Property
The response is nothing but the output which will be passed/responded back to source post execution of custom logic
![]()
Steps to implement Custom Logic
- Need to create the Custom Assembly in Visual Studio
- The same we do for writing a custom plugin in Dynamics CRM
- Register the assembly using the Plugin Registration Tool
- And then need to bind the plugin class file to the Custom API
- public class ContactQualify : IPlugin
- {
- public void Execute(IServiceProvider serviceProvider)
- {
- ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
- IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
-
- {
-
-
- IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
- IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
-
- try
- {
- tracingService.Trace(context.InputParameters["sum_Target"].ToString());
- Entity userDetails = service.Retrieve("systemuser", context.UserId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
- tracingService.Trace(context.MessageName);
- tracingService.Trace(context.Stage.ToString());
- context.OutputParameters["sum_CustomParameter2"] = userDetails.GetAttributeValue<string>("fullname");
-
-
- }
- catch (Exception ex)
- {
- tracingService.Trace("FollowUpPlugin: {0}", ex.ToString());
- throw;
- }
- }
- }
- }
Steps to execute the Custom API
- Write a simple console application
- Connect to Common Data Model using organization service and valid credentials
- And just use the below code to execute the Custom API
- try
- {
- if (service != null)
- {
- var req = new OrganizationRequest("sum_CustomAPI2") //Name of Custom API
- {
- ["sum_Target"] = "Sumit" //Input Parameter
- };
- var resp = service.Execute(req); //resp will have output parameter
-
- }
- }
-
- catch (Exception ex)
- {
- Console.Write(ex.ToString());
- }