In Power Automate you can use the Dataverse connector to access data in Dataverse, and it even supports calling bound and unbound APIs. Unfortunately, not all REST API endpoints are available inside the connector, and the Dataverse connector also doesn't have support for impersonating another user. Luckily this can easily be resolved differently!
Call the WhoAmI endpoint
One of the most known and used endpoints is the WhoAmI endpoint, which will respond with information about the calling user. It's the easiest way to validate whether the Dataverse connection is working. Funnily enough, it's not available inside the Dataverse connector so it's ideal as an example for this technique.
- Edit the flow where you want to call the Dataverse REST API. In my example, I'm using a simple flow using the Manually trigger a flow trigger.
- Add another action and search for HTTP with Microsoft Entra ID
- It's very important to select the HTTP with Microsoft Entra ID (preauthorized), the non-preauthorized version does not work for this scenario (you can make that one work too with the steps in the docs). Select the Invoke an HTTP request action.
- Fill in the connection parameters. In both boxes, you have to enter the URL to your Dataverse environment (do not end with a /), eg. https://contoso.crm4.dynamics.com, and select the Sign in button. Authenticate with your user account.
- Now you can select Method and enter the Url of the request. In my case, I want to do a Get request to the
/api/data/v9.2/WhoAmI
endpoint.
- Test your flow and see the result!
Call the WhoAmI endpoint with impersonation
An extra advantage of calling the REST APIs directly is the ability to impersonate other users while executing this call. Of course, the calling user needs to have the permission to impersonate other users! Read the docs to learn more about impersonating another user in a REST API call to Dataverse.
The only way to properly validate is by doing a POST request creating a record, and comparing the
createdby
and createdonbehalfby
properties of the new record.Impersonate a user based on their Microsoft Entra ID object id
This is, according to Microsoft, the preferred way of doing impersonation and requires you to know the object id of the user in Microsoft Entra ID.
- Adjust the Invoke an HTTP request action by adding a header in there. As key value for the header you should put
CallerObjectId
, and as value use the object id.
- Test your flow and see the result!
Impersonate a user based on their systemuserid
According to Microsoft, this is the legacy way of doing impersonation and it uses the id of the user in the systemusers
table.
- Adjust the Invoke an HTTP request action by adding a header in there. As key value for the header you should put
MSCRMCallerID
, and as value use the systemuserid.
- Test your flow and see the result!