How to create Custom API in Common Data service

Custom APIs are an extension of a custom action that can provide a no-code way to include custom messages. CDS have workflow custom action which can help create a new plugin message and we can register the plugin on those custom message and execute any logic server-side. These custom actions can either be called from the custom workflow, plugin, or can be triggered by client-side web API calls. As an extension of the custom action, Microsoft has release Custom API in preview which provides many more features and control and security on custom API.


CapabilityCustom ActionCustom API
Create Or Modify using a solutionNoYes
Bind Operation to entity collectionNoYes
Bind Operation to the entityYesYes
Create global operationYesYes
Create Odata functionNoYes
Making message privateNoYes
Block extension by another pluginNoYes
Require specific privilegesNoYes

Scenario:

We need a custom API that needs to count the number of characters in a string and it should be only allowed to the user having privilege "prvReadAccount".

  1. Create a solution and add a new "Custom API"

Fill attributes as below

  • Binding Type: Global (Since we do not want to bind to an entity)
  • Is Function: No (We are creating an action which takes a parameter in the body and can be called using the POST method)
  • Allow custom processing step type: This defines which type of plugin can be registered on custom API. We have selected none so we don't want anyone else to register on custom api.
  • Execute Privilege Name: "prvReadAccount" (Calling user must have this privilege if left blank user privilege is not checked).
  • Plugin Type: Keep blank for now, need to select the plugin type once we deploy our plugin.


 2. Define custom API request parameter

I have created a parameter with the name "instring" of type string.


   3. Define custom API response parameter
I have created a parameter with the name "charCount" of type string.



4. Create Plugin

Here we are checking if MessageName is "new_countcharacters" and performing the action.

Now as we have created the plugin, let's go ahead and register it.




After registering the plugin we need to update Custom Api for "Plugin Type"


Testing Custom Api (I am using CRM rest builder of testing)




Hope this was helpful, Happy learning. 

Post a Comment

0 Comments