SharePoint 2013 - 访问资源AuditLogs

时间:2017-09-22 18:06:11

标签: rest sharepoint sharepoint-2013 audit-logging

我希望通过API提取以下列出的资源上的审核日志。

应根据库设置打开审核日志,但我似乎无法找到获取详细信息的正确路径。建议表示赞赏。

API致电

https://collab.iad.ca.inet/teams/OPPE/Operational Performance Tools/_api/Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)

当前回复

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="https://collab.iad.ca.inet/teams/OPPE/Operational%20Performance%20Tools/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag="&quot;5&quot;">
    <id>4fb4f10c-3abc-4c4e-b501-fe97d5072e1d</id>
    <category term="SP.Data.Shared_x0020_DocumentsItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject" type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FirstUniqueAncestorSecurableObject" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments" type="application/atom+xml;type=feed" title="RoleAssignments" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/RoleAssignments" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/AttachmentFiles" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/ContentType" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/GetDlpPolicyTip" type="application/atom+xml;type=entry" title="GetDlpPolicyTip" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/GetDlpPolicyTip" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml" type="application/atom+xml;type=entry" title="FieldValuesAsHtml" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FieldValuesAsHtml" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText" type="application/atom+xml;type=entry" title="FieldValuesAsText" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FieldValuesAsText" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit" type="application/atom+xml;type=entry" title="FieldValuesForEdit" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FieldValuesForEdit" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File" type="application/atom+xml;type=entry" title="File" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/File" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folder" type="application/atom+xml;type=entry" title="Folder" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/Folder" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ParentList" type="application/atom+xml;type=entry" title="ParentList" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/ParentList" />
    <title />
    <updated>2017-09-22T17:32:14Z</updated>
    <author>
        <name />
    </author>
    <content type="application/xml">
        <m:properties>
            <d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
            <d:Id m:type="Edm.Int32">1</d:Id>
            <d:ContentTypeId>0x010100ABBF36DE0421214A8F4689DD7BB5FC63</d:ContentTypeId>
            <d:Title>Intact Pro-Rata Calculator</d:Title>
            <d:SharedWithUsersId m:null="true" />
            <d:ID m:type="Edm.Int32">1</d:ID>
            <d:Created m:type="Edm.DateTime">2017-09-01T21:52:45Z</d:Created>
            <d:AuthorId m:type="Edm.Int32">15</d:AuthorId>
            <d:Modified m:type="Edm.DateTime">2017-09-21T22:59:39Z</d:Modified>
            <d:EditorId m:type="Edm.Int32">15</d:EditorId>
            <d:OData__CopySource m:null="true" />
            <d:CheckoutUserId m:null="true" />
            <d:OData__UIVersionString>5.0</d:OData__UIVersionString>
            <d:GUID m:type="Edm.Guid">4fe5308e-c8a9-469c-ae58-db4c3b9e8a1b</d:GUID>
        </m:properties>
    </content>
</entry>

1 个答案:

答案 0 :(得分:0)

通过CSOM / REST API无法使用 Audit API 。可以使用提供类似功能并通过CSOM / REST API公开的SP.Change class

以下示例演示了如何检索每个列表的更改并打印更改时间和类型名称:

var listTitle = "Documents";

var changeQuery = {
    "Add":true,
    "Update":true, 
    "DeleteObject":true,
    "File":true,
    "Item":true
};

getListChanges(_spPageContextInfo.webAbsoluteUrl,listTitle, changeQuery)
.then(function(data){
    data.d.results.forEach(function(item){
         console.log(item.Time + ":" + getChangeTypeName(item.ChangeType));
    });
})
.fail(function(error){
    console.log(error);
});

,其中

function getListChanges(webUrl,listTitle,changeQuery) 
{
    var payload = {
         'query' : changeQuery
    };
    payload.query['__metadata'] = { 'type': 'SP.ChangeQuery' };

    var properties = {
         webUrl: webUrl,
         requestUrl:  "/_api/web/lists/getbytitle('" + listTitle + "')/getchanges", 
         payload: payload,
         action: "InvokeMethod"  
    };
    return executeRequest(properties);
}

function getChangeTypeName(id){
    var mappings = {
        1 : "Add",
        3 : "DeleteObject",
        2: "Update"
    }
    return mappings[id];
}


function executeRequest(options) {
    options.headers = options.headers || {};
    options.headers["Accept"] = "application/json;odata=verbose";
    options.headers["Content-Type"] = "application/json; odata=verbose";
    options.headers["Accept-Language"] = _spPageContextInfo.currentCultureName;
    options.action = options.action || "Read";

    switch (options.method) {
        case "Update":
            options.headers["IF-MATCH"] = "*";
            options.headers["X-HTTP-Method"] = "MERGE";
            break;
        case "Delete":
            options.headers["IF-MATCH"] = "*";
            options.headers["X-HTTP-Method"] = "DELETE";
            break;
    }

    var ajaxOptions =
        {
            url: options.webUrl + options.requestUrl,
            type: options.method == "Read" ? "GET" : "POST",
            headers: options.headers
        };
    if ("payload" in options) {
        ajaxOptions.data = JSON.stringify(options.payload);
        ajaxOptions.type = "POST";
    }
    if(options.action != "Read"){
        ajaxOptions.headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
    }
    return $.ajax(ajaxOptions);
}