Creating Custom API in D365.

Hello Guys,

In our previous blog we have seen how to retrieve and use GUID of logged in user in canvas application. Today we are going to create custom API which is nothing but the custom action in old version of the CRM.



But before do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.

Custom API is a new way of creating Custom Action messages in D365. We were used to create a custom action for custom messages in previous version of the CRM for many years. Below image shows the example of custom action.




But now Microsoft has introduced an extension for Custom Action called Custom API which has more controls like creating Private Custom API which means API can be used by owner of the API or by users with whom API is shared. We can create Custom API as web method which means we can use GET and POST method to use this API.

Custom API does not require us to create custom messages which were creating previously instead we need to configure records in Custom API entity.

Let's see how to create custom API and how to register plugin on it. Here we will be creating a plugin which will update address based on Account in Contact entity.
Start Visual Studio and create one plugin as shown below and register it:





Now we will be creating Custom API. Click on https://make.powerapps.com and select your environment. Now open the solution and click on new.




Scroll down and click on Custom API.




This will open a new window. Specify the info as shown below:





Click on Save and Close. 

Now we will be creating Custom API Request Parameter. In our scenario we have to create two parameter of type Entity Reference. One for Account and another for Contact as you can see in above code we have used these both parameter.

Click on New and select Custom API Request Parameter.




Fill the info as shown below:





So now we are done with creating API and Request Parameters. Now we will be calling this Custom API using another plugin which will be trigger when a new contact record will be created(Post operation).

Create a new plugin file as shown below and register it.





Now we will be creating a new record and check whether this API is updating address in contact or not.





While creating Custom API,

Unique Name: Unique name for the Custom API which should start with the publisher’s prefix which you have specified on your solution.

Name: Name for the Custom API.

Display Name: Display Name for this Custom API.

Description: This field is to store the description of this Custom API.

Binding Type: The Binding Type is the Options set field and could be set as Global, Entity, and Entity Collection. This should be specified as per your operation requirement (Entity Collection is only supported in Function Type Custom API).

Bound Entity Logical Name: This field is required when we select the Binding Type as Entity or Entity Collection. For the binding type as Global, it can be empty.

Is Function: It defines whether your custom API is a Web method which can only be called using Get method or Action which can only be called using POST method.

Is Private: To define the Custom API is private or public. If it is private then it can be access by owner only.

Allowed Custom Processing Step Type: Allowed Custom Processing Step Type is another Option set field with options like None, Async Only, Sync, and Async. These options let you define whether the other plugins could be registered on this Custom Message and also lets you define its behavior. Like Async Only allows the plugins to register only onPost operation with Execution Mode to Asynchronous, and same for the Sync and Async option.

Execute Privilege Name: We can define the privilege that allows execution of the custom API. As per Microsoft docs, we can also create custom privileges and it is currently in development. We can use OOB privileges, for example,prvCreateLead, prvWriteLead, etc.

Plugin Type: Reference of plugin for this API.

While creating Custom API Request Parameter we need to specify below details:

Custom API: Reference of your Custom API record.

Unique Name: Unique name for the parameter.

Name: Name of the custom API Request Parameter that shall be visible on the solution.

Display Name: Display Name for this Custom API Request Parameter which shall be used to called this Custom API from the App.

Description: This field is to store a description of this Parameter.

Type: Parameter type as per your requirement. Below are the currently available data type options for Custom API.

  • Boolean
  • Date and Time
  • Decimal
  • Entity
  • Entity Collection
  • Entity Reference
  • Float
  • Integer
  • Money
  • Picklist
  • String
  • String Array
  • GUID
Logical Entity Name: Logical Entity Name if you want to use parameter bounded with any specified entity. You can set this field only with Entity and Entity Reference Type of Parameter.

Is Optional: Whether parameter is optional or required.

Hope it helps...

Comments

  1. Hello RavishChandra Gupta,

    You are calling your custom API using a plugin which is registered on create of contact , Will it update the address in Contact when a user update address in Account entity because we are not calling this API on that event?

    Secondary it is bot easy scenario and we can achieve it other easy ways as well.

    Can you provide us a scenario where we can prefer Custom API and that part can not be achieved using other general ways of dev?

    ReplyDelete
    Replies
    1. Hello Vaibhav,

      This is just for demonstration purpose like how to create and use custom API. And answer to your question whether this will update the address in Contact when a user update address in Account then No its not going to update as we have registered our plugin on create of Contact. If you want it should update the address then we should call the same API on updation of Account.

      Delete

Post a Comment

Popular posts from this blog

Read Only Sub Grid & Editable Sub grid in Dynamics 365

Using Pipelines in Power platform for deploying solutions to environments.

Understanding Sales Process in D365.