web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get the audit log of an entity in CRM 2016 using a web API

(0) ShareShare
ReportReport
Posted on by

I have made a lot of research to get the log of changes for a specific entity using Microsoft dynamics CRM 2016 web API in , but that's useless I cannot find a way to did that.

I just found the RetrieveAuditPartitionLis which return collection of partitions, Response :

"AuditPartitionDetailCollection": [
{
"PartitionNumber": 1,
"StartDate": "2014-07-01T00:00:00Z",
"EndDate": "2014-09-30T19:59:59.997-04:00",
"Size": 9
},
{
"PartitionNumber": 2,
"StartDate": "2014-10-01T00:00:00Z",
"EndDate": "2014-12-31T18:59:59.997-05:00",
"Size": 8
},


.....

I need a way to get the log of a specific entity for example /accounts/audit endpoint. How to achieve that?

*This post is locked for comments

I have the same question (0)
  • Saroj Das Profile Picture
    3,355 on at

    HI,

    You need View Audit History security role to view the audit history for individual entities.

    And Check these.

    msdn.microsoft.com/.../gg328218.aspx

    msdn.microsoft.com/.../gg309735.aspx

    Thanks,

    Saroj

  • Community Member Profile Picture
    on at

    Sarjo,

    I know theses messages/application API are specific in C# , but I don't have access to the CRM server, and I don't know C# at all. I just need a WEB API endpoint to get the audit/log of a specific entity, for example log of accounts table.

    is that possible without using the C# API you refer to?

    If not how can detect the deleted rows/resources in entities?

    Thanks,

  • Verified answer
    Community Member Profile Picture
    on at

    Have you install the Solution CRMRestBuilder By Jason Lattimar? if not plz install this solution in CRM.

    CRM RestBuilder Basically build a query for CRM 2016 Web API.

    I have created a Simple query using this solution

    Here a sample sudo code retrieve all audit against the record of account.

    Basically Audit is main Enitity and regardingobject id is id of the entity which record you want to retrieve.

    plz try this tool and try yourselft to make query.

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/audits?$select=action,auditid,createdon,operation,_regardingobjectid_value&$filter=action eq 2 and  _regardingobjectid_value eq 7b50FF5165-6EDC-E411-9905-6C3BE5A8CE", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                for (var i = 0; i < results.value.length; i++) {
                     var action = results.value[i]["action"];
                     var action_formatted = results.value[i]["action@OData.Community.Display.V1.FormattedValue"];
                     var auditid = results.value[i]["auditid"];
                     var createdon = results.value[i]["createdon"];
                     var operation = results.value[i]["operation"];
                     var operation_formatted = results.value[i]["operation@OData.Community.Display.V1.FormattedValue"];
                     var _regardingobjectid_value = results.value[i]["_regardingobjectid_value"];
                     var _regardingobjectid_value_formatted = results.value[i]["_regardingobjectid_value@OData.Community.Display.V1.FormattedValue"];
                }
            }
            else {
                alert(this.statusText);
            }
        }
    };
    req.send();

    RestBuilder.PNG
  • Community Member Profile Picture
    on at

    Mohammed thank you very much, I have test this api before but I forget to write audit in plural form.

    I'm using postman.  I'm new to CRM and I have access to the online CRM web application how can I add tool you mentioned, could you direct me to the instructions please. Also Can you give me a link to the specification of the audit entity.

    Here's what I have revived from audits entity :

    {

    "_objectid_value": "00000000-0000-0000-0000-000000000000",

         "_userid_value": "82de60d1-362a-e411-80c1-00155d002810",

         "operation": 3,

         "createdon": "2014-09-16T19:05:36Z",

         "auditid": "da3f5570-d43d-e411-80c2-00155d002810",

         "attributemask": "10003",

         "action": 101,

         "transactionid": "b0785070-d43d-e411-80c2-00155d002810",

         "useradditionalinfo": null,

         "_regardingobjectid_value": null,

         "_callinguserid_value": null

    }

  • Verified answer
    Community Member Profile Picture
    on at

    Step1. Download the Solution CRMRestBuilder.

    Step2. In CRM go to Settings>Customization>Solutions>Click Import button on All Solutions view

    and Browse for (Select)the downloaded solutions as in step 1 and Click next to install the solution.

    Step3. When solution installed successfully Open the CRMRestBuilder solution from CRM by selecting the installed solution.

    Step4. Make Query as per your requirement by selecting Entity,condition and type of retrieve single or multiple and other options

      

  • Community Member Profile Picture
    on at

    I have imported the CRMRestBuilder, but when I open the solution it open new window and the following message "You cannot directly edit the components within a managed solution. If the managed properties for solution components are set to allow customization, you can edit them in the Customizations area or from another unmanaged solution." are shown, and there's an iframe that said Unable to resolve the server's DNS address.

  • Community Member Profile Picture
    on at

    Hi Mohammed, I tried to run such as query. eg:

    https://myserver.crm4.dynamics.com/api/data/V8.2/audits$filter=action eq 2 and  _regardingobjectid_value eq 969b54ca-d8ee-e611-80f9-5065f38a9a01

    (with a valid Bearer-Token) and got the response:

    Status: 403  and the 

    {
      "error": {
        "code": "",
        "message": "RetriveMultiple call on Audit Entity must specify exactly one Condition set on objecttypecode at the top level filter",
        "innererror": {
          "message": "RetriveMultiple call on Audit Entity must specify exactly one Condition set on objecttypecode at the top level filter",
          "type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
          "stacktrace": "
       at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.RetrieveMultiple(QueryBase query, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)
       at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.RetrieveMultiple(QueryBase query)
       at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, String castedEntityName, ODataQueryOptions queryOptions)
       at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)
       at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"


    Any suggestions?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans