Microsoft has recently released preview of Dataverse Custom API. Previously we had Custom Actions which can be called like a custom API. Custom Actions could be bound to a particular entity or remain global/unbound. They were dependent on the workflows and could be treated as a message in the plugin registration tool.
Dataverse custom API is also leveraging the same pattern, however it has some additional capabilities and some differences as well.
- It is not dependent on workflows.
- It can be created as private.
- It is an OData web service with the POST method called an Action and GET method called a Function.
Creating the Dataverse API from maker portal.
Let us create a new solution.
![Creating Dataverse Custom API](https://optimallogics.com/wp-content/uploads/2020/12/1-2.png)
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/2-2.png)
In the solution we will add a ‘Custom API’:
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/3-1-1024x324.png)
After creating the Custom API, it will not display in the solution. So, we will have to add it to our solution. For adding this click Add existing and then select Custom API from the drop-down list.
![Creating Dataverse Custom API](https://optimallogics.com/wp-content/uploads/2020/12/add-existing-customapi-1-1024x613.png)
It will ask for Name, Description, Binding Type (Global or bound), isFunction(GET or POST), Allowed Custom Processing Type (None, Sync and Async, Async only) etc. Further explanation of these parameters can be found here.
![Creating Dataverse Custom API](https://optimallogics.com/wp-content/uploads/2020/12/4-2.png)
We will then add a request parameter:
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/12-1.png)
![Creating Dataverse Custom API](https://optimallogics.com/wp-content/uploads/2020/12/5-4.png)
and a response property:
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/12-2.png)
![Creating Dataverse Custom API](https://optimallogics.com/wp-content/uploads/2020/12/6-3.png)
If we look at the metadata, we can see our API:
https://{orgname}.crm.dynamics.com/api/data/v9.1/$metadata
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/7-1-1024x468.png)
Now we will write a plugin for the API:
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/8-1.png)
and register the plugin with the API, please note that we do not need to add a stage to the plugin.
After registering the plugin, we need to set the ‘PluginType’ of the custom API:
![Creating Dataverse Custom API](https://optimallogics.com/wp-content/uploads/2020/12/9-3.png)
Now if we run the function https://{orgname}.crm.dynamics.com/api/data/v9.1/{functionname} in Postman we will see the result.
![Creating CDS Custom API](https://optimallogics.com/wp-content/uploads/2020/12/10-1.png)
Please note that Custom API is similar to Custom Actions in some aspects but it has much more control and flexibility in terms of permissions and parameters.
For questions or insights, leave a comment below or reach out to us at info@optimallogics.com. We are always happy to help.