How to use the Dataverse Web API
In this article I am going to demonstrate how you can use the Dataverse Web API within a Power Automate flow. In this example a description of a phone call activity is updated. This is a note to self kind of article.
Table as a variable
In the Power Automate community Stanza asked help with specifying a table name dynamically by using a variable. However, this didn’t work with the out of the box Update a record action.
As far as I am aware this is a limitation of that Update a record action. However, it is possible to connect to Microsoft Dataverse tables directly via the Web API.
Register an App with Azure AD
Before you continue to the Power Automate setup you need to be able to communicate with the Dataverse Web API.
First step is to register an app in Azure Active Directory. Elaiza Benitez has written a nice blogpost about this, How to authenticate as an application with Microsoft Graph API with flow.
The only difference is that you need to select the Microsoft Dataverse permissions instead of the Graph Permissions.
Update 09-07-22: Since I published this article the Power Platform admin interface has slightly changed. Follow these steps instead for the creation of an application user.
When you are interacting with the phonecall table you are dealing with a Customer Engagement table. To interact with this kind of data you need to setup an additional application user within your Dynamics 365 Customer Engagement environment.
1. Go to the Org url, something like https://org.crm.dynamics.com
2. Go to Gear Icon and find the Advanced Settings.
3. Navigate to Settings > Security > Users
4. Switch to Application Users view.
5. Click New.
6. Enter the Client Id of the Azure AD App in the Application ID field and save the record
7. Assign a Role, via Manage Roles
When you have created the Azure AD app and the application user you should be able to use an HTTP action to interact with the Web API. Below is an example of that.
1. Add a HTTP action. The method is PATCH and in the URI field I am using the Microsoft Dataverse Web API. I am also using a variable for the entity, making this a flexible solution.
2. In the body you can set for instance the description field. Below is a public gist with the configuration I used in my HTTP action.
3. For the authentication I am using OAuth with a couple of variables for the audience, client id and the secret.
That should be it. Happy testing!