Using an Azure Function
You could perform a HTTP request to the Dataverse web API using the audits
entity set name. The request would look something like:
GET /api/data/v9.2/audits HTTP/1.1
Host: {organizationUniqueName}.{region}.dynamics.com
Authorization: Bearer eyJ0eXAi...
Note, you need to provide a bearer authentication token in the request (See Use OAuth authentication with Microsoft Dataverse for details on how to do that. See Query data using the Web API for a comprehensive guide on querying the Dataverse web API.
Alternatively, you could use either one of the below NuGet packages to query Dataverse using C#.
- Microsoft.CrmSdk.CoreAssemblies (Only works with Azure Function runtime 1.x)
- Microsoft.PowerPlatform.Dataverse.Client (Public preview. Works with runtime 2.x+)
Regardles of the package you choose to use, the C# code will look more or less the same with the exception of ServiceClient
being applicable to the second NuGet package, and CrmServiceClient
applying to the first package.
var client = new CrmServiceClient(connectionString);
var auditLogsQuery =
@"<fetch top='50' >
<entity name='audit' >
<filter>
<condition attribute='operation' operator='eq' value='1' />
<condition attribute='createdon' operator='last-x-hours' value='1' />
</filter>
</entity>
</fetch>";
EntityCollection auditLogs = client.RetrieveMultiple(new FetchExpression(auditLogsQuery));
Using Power Automate
Seeing as you have mentioned the use of Power Automate, I suggest you consider using it to meet your requirements. Querying data in Dataverse is native to Power Automate through the built-in Dataverse connector.
Lets say you have the below Fetch XML query to pull back all audit logs where the operation was Create
(1) and the operations were performed in the last hour.
Tip: You can use the FetchXML Builder plugin in the XrmToolBox to author these queries. Querying the audit logs in the advanced find is not supported.
<fetch top="50" >
<entity name="audit" >
<filter>
<condition attribute="operation" operator="eq" value="1" />
<condition attribute="createdon" operator="last-x-hours" value="1" />
</filter>
</entity>
</fetch>
Using the Dataverse List rows
action, you can specify you want to query the Audits
table and provide the above Fetch XML query in the Fetch Xml Query
property of the action. See below for an example:

The results of this query are now available throughout the Power Automate cloud flow. For example, here I am using the Compose
action to write out the Operation
, Record Type
, Record ID
, and Changed Field
for the returned audit logs.
