Create Custom APIs in Dynamics 365 CRM | Power Platform

Custom APIs in Dataverse is a great way to build your own API messages to encompass complex business operations into a single API. And Power Platform Admin Center provides a great way to keep things simple and yet build your custom APIs just like writing Plugins in Dynamics 365 CRM itself.

Pre Requisites

In order to build your own APIs, you must know the following –

  1. Writing Plugins in Dynamics 365 CRM – In case you are new to plugin development itself, you can follow this blog series wherein I’ve demonstrated how you can start writing your own C# Plugins for Dynamics 365 CRM.
    Link: Plugins Development in Dynamics 365 CRM for Beginners | [Blog Series]
  2. You’ll also need to know how to connect Postman to your Dynamics 365 CRM environment in order to test your APIs before you can use it in your custom application. I have a blog for the same as well.
    Link: Setup Postman to connect to Dynamics 365 CRM using OAuth 2.0 | Azure App Registration

Scenario

Here’s a scenario where I’ll demonstrate how you can use Custom API to do an operation in Dynamics 365 CRM and send back result to the calling application.

  1. Custom API is exposed to the calling application. Postman in this case.
  2. Once API is called and parameters is passed, a simple update of a field to an Account will take place.
  3. Result will be returned to the calling application. Again, Postman in this case.

Create your Custom API & Parameters in Power Platform Admin Center

Let’s create a Custom API that’ll pass on parameters to a plugin and plugin in-turn will send back the result itself –

  1. Assuming you have created a Solution in the correct Dynamics 365 / Dataverse environment. Click on New, and look for Custom API.

  2. Give it a suitable Name and fill in the Attributes which are required. Here, the unique name of the API is cf_processaccountapi.
    I will cover the other properties in a different blog post.

  3. Now, I’ll create 2 attributes which I need to pass as parameters to the API call itself.
    Hence, I’ll now create 2 new API Request Parameters in the solution by following the below menu.

  4. First will be the Account Code. I’ll select the Process Account API from the Custom API lookup on the form and then give unique name.
    Here, my parameter is of type String.

  5. And once I save this, this is how my parameter 1 i.e. Account Code is supposed to look.

  6. Similarly, my second parameter is as follows which accepts a String value. This parameter is called Grade Code. Again, this is just an example. Your scenario could be anything.

  7. Finally, I’ll also create a Response Property for the Custom API in order to send back the response to the caller.

  8. And just like how I defined the Request Parameters, I’ll also create the Response property as below.
    The form is quite self-explanatory by now.


  9. Once all of this is done, here’s how my API structure looks like in the solution.

Sample Plugin for Custom API & Registering it using Plugin Registration Tool

Given that you know how to work with Plugins in Dynamics 365 CRM, here’s how you can register the plugin as usual –

  1. In my plugin, I’m capturing the values from the attributes just like I would identify the context of a Plugin which runs on Update of an Account.

  2. Then, I’m finding the Account using the Account Code that was passed and updating that Account with the Option Set value which will be the Grade Code.

  3. Then, once all the processes are done, I’m setting the Output Parameter accountProcessResult with the success message.


  4. Open the Plugin Registration Tool and log into your environment. Then, Register the Assembly itself.

  5. Once your plugin has been registered, you’ll need to open the Custom API record again and associate this registered plugin on the Custom API record.
    Open the Custom API record which we created above –

  6. When you associate the Plugin Type, make sure you Save and Publish the customization.
  7. Now, we will test using Postman. Before we test, notice the Account Grade column which is of type OptionSet – we will update this using the Custom API we built.


    The OptionSet fields looks like below –

Testing Using Postman

Now that the code for the Custom API is ready as well as the Plugin too has been registered, let’s test the same using Postman –

  1. Again, in case you haven’t set the Postman to authenticate and connect to your D365 CRM environment, you can follow this post and set up your Postman to be able to call Dynamics 365 CRM.
    Link: Setup Postman to connect to Dynamics 365 CRM using OAuth 2.0 | Azure App Registration
  2. Now, given that you were able to successfully connect Postman to Dynamics 365, you can do a simple metadata call and check if you connection was successful.

  3. Now, look at the unique name of the Custom API we created.
    Now, switch the method to Post, and append the name of the Custom API itself.
    Then, in raw – select JSON type data and construct the JSON to be sent.

  4. And the result will be returned based on what Output Parameters was set.

  5. And you’ll see the data on the OptionSet being updated through this example.

Hope this was useful and this helped in clarifying the concept!

Here are some Power Automate posts you want to check out –

  1. See Trigger Outputs using Edit Columns in Flow Runs | Power Automate [Quick Tip]
  2. Adding Image field on the form in Dynamics 365 CRM | Power Platform Modern Form Designer [Quick Tip]
  3. Blocking Attachment Extensions in Dynamics 365 CRM
  4. Upgrade Dataverse for Teams Environment to Dataverse Environment
  5. Showing Sandbox or Non Production Apps in Power App mobile app
  6. Create a Power Apps Per User Plan Trial | Dataverse environment
  7. Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
  8. Co-presence in Power Automate | Multiple users working on a Flow
  9. Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
  10. Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
  11. Call a Flow from Canvas Power App and get back response | Power Platform\
  12. FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
  13. Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
  14. Asynchronous HTTP Response from a Flow | Power Automate
  15. Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
  16. Converting JSON to XML and XML to JSON in a Flow | Power Automate

Thank you!

2 thoughts on “Create Custom APIs in Dynamics 365 CRM | Power Platform

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.