【问题标题】:Accessing specific changeItem using Sharepoint REST API使用 Sharepoint REST API 访问特定的 changeItem
【发布时间】:2014-09-13 09:19:50
【问题描述】:

我正在尝试使用;

得到 * https://{sitecollection}/{personal/user_name_domain_onmicrosoft_com}/_api/web/getchanges('query')/item

参考

http://msdn.microsoft.com/en-us/data/jj246759(v=office.12).aspx

http://msdn.microsoft.com/en-us/library/office/jj246759(v=office.15).aspx

我无法让它工作,也找不到任何这个调用的例子。

我正在尝试类似的东西;

获取

  • https://{sitecollection}/{personal/user_name_domain_onmicrosoft_com}/_api/web/getchanges('Add=true,Item=true')/item

  • https://{sitecollection}/{personal/user_name_domain_onmicrosoft_com}/_api/web/getchanges(query='Add=true,Item=true')/item

但没有运气。

仅供参考::我不想通过这个电话获取变更日志。我正在尝试获取单个更改项。但是由于语法是这样的,所以我在这些大括号中放了一个随机查询。 /getchanges(这是一个 POST 调用)工作正常。

有什么帮助吗?

【问题讨论】:

    标签: sharepoint ms-office office365 changelog


    【解决方案1】:

    至少有两个选项可以构造ChangeCollection端点的请求:

    选项 1

    通过请求正文发布ChangeQuery

    function getChanges(webUrl,queryOptions,success,failure)
    {
       var changeQueryPayload = { 
           'query':{ 
               '__metadata': { 'type': 'SP.ChangeQuery' },  
            } 
       };
       for(var key in queryOptions) {
           changeQueryPayload['query'][key] = queryOptions[key];
       }
    
       $.ajax({
          type: "POST", 
          headers: { 
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
          }, 
          data: JSON.stringify(changeQueryPayload),
          url: webUrl + '/_api/web/getchanges', 
          success: success,
          failure: failure 
       });
    }
    

    选项 2

    通过查询字符串传递ChangeQuery 表达式:

    function getChanges(webUrl,queryOptions, success,failure)
    {
       $.ajax({
          type: "POST", 
          headers: { 
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
          },
          url: webUrl + '/_api/web/getchanges(@qry)?@qry=' + JSON.stringify(queryOptions) + , 
          success: success,
          failure: failure 
       });
    }
    

    示例

    检索网络更新:

    var queryOptions = {"Update":true,"Web":true};
    
    
    getChanges(_spPageContextInfo.webAbsoluteUrl,queryOptions,
      function(result){
          var changes = result.d.results;
          //print info
          console.log('Found ' + changes.length + ' items');   
      },
      function(error){
         console.log(JSON.stringify(error)); 
      }); 
    

    关于请求特定的更改项,可以从 REST 服务返回的结果中检索。

    【讨论】:

    • 如何在 react typescript 中使用 httpClient 或 spHttpClient 在 typescript 中编写上述代码? var query = JSON.stringify('{"Update":true,"Web":true}'); const reqH: Headers = new Headers(); reqH.append('接受', 'application/json;odata=verbose'); const httpClientOptions: IHttpClientOptions = { headers: reqH };变种网址 = ${this.siteUrl}/_api/web/getChanges; this.httpClient.post(url,HttpClient.configurations.v1, httpClientOptions)
    【解决方案2】:

    有一个例子: http://msdn.microsoft.com/en-us/library/office/dn499819(v=office.15).aspx

    executor.executeAsync({
      url: "<app web url>/_api/SP.AppContextSite(@target)/web/getchanges?@target='<host web url>'",
      method: "POST",
      body: "{ 'query': { '__metadata': { 'type': 'SP.ChangeQuery' }, 'Web': true, 'Update': true } }",
      headers: {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose"
      },
      success: successHandler,
      error: errorHandler
    });
    

    【讨论】:

    • 我已经更新了我的问题。这是一个差异调用(POST 调用),对我来说效果很好。我对单个项目 (ChangeItem) 感兴趣,因为您可以在我尝试的通话结束时看到 /item。
    • @SyedMauzeRehan 你能拿到单件吗?你是怎么解决这个问题的。我有一个类似的问题,我需要知道 SP.ChangeItem 的详细信息
    • 我能够获取单个项目,但这并没有返回我想要的所有数据 _api/web/Lists/getbytitle('Documents')/items?$filter=Id eq 48
    • 不,那是物品本身。我一直在寻找整个变化事件。即,更改日志中的更改提供了有关它的所有详细信息。现在,我只得到受影响的列表、项目 ID、更改类型等。我正在寻找更详细的内容但找不到。
    【解决方案3】:

    请参考https://msdn.microsoft.com/en-us/library/office/dn499819.aspx

    以下代码对我有用。

    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getchanges", 
        type: "POST",
        data: "{ 'query': { '__metadata': { 'type': 'SP.ChangeQuery' },'Web': true, 'Update': true, 'Add': true } }",
        headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose",'X-RequestDigest':$('#__REQUESTDIGEST').val() },
        success: successHandler,
        error: errorHandler
    });
    
    function successHandler(data, textStatus, jqXHR ){
        alert("successHandler " + "textstatus:" +textStatus + "data: " + data);
    }
    
    function errorHandler(xhr, ajaxOptions, thrownError) {
        alert('Request failed: ' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-23
      • 2014-07-25
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 2019-01-04
      • 2019-05-17
      • 2013-12-29
      相关资源
      最近更新 更多