【问题标题】:Remove properties related to Sharepoint from raw odata response从原始 odata 响应中删除与 Sharepoint 相关的属性
【发布时间】:2015-08-19 20:46:51
【问题描述】:

我正在使用 Sharepoint REST API 从 NodeJS 获取/修改 Sharepoint 中的数据。

我收到了来自 Sharepoint REST API 的 odata 响应,并且一切都按预期工作。 除了一件事。

目前我收到了来自 Sharepoint REST API 的响应,如下所示

{
    "odata.metadata": "https://test.sharepoint.com/_api/$metadata#SP.ApiData.Lists",
    "value": [
        {
            "odata.type": "SP.List",
            "odata.id": "https://test.sharepoint.com/_api/Web/Lists(guid'sample-guid')",
            "odata.etag": "\"6\"",
            "odata.editLink": "Web/Lists(guid'sample-guid')",
            "AllowContentTypes": true,
            "BaseTemplate": 160,
            "BaseType": 0,
            "ContentTypesEnabled": true,
            "CrawlNonDefaultViews": false,
            "Created": "2015-05-19T11:13:46Z",
            "DefaultContentApprovalWorkflowId": "00000000-0000-0000-0000-000000000000",
            "Description": "Use this list to track access requests to a site or uniquely permissioned items in the site.",
            "Direction": "none",
            "DocumentTemplateUrl": null,
            "DraftVersionVisibility": 0,
            "EnableAttachments": false,
            "EnableFolderCreation": false,
            "EnableMinorVersions": false,
            "EnableModeration": false,
            "EnableVersioning": true,
            "EntityTypeName": "AccessRequests",
            "FileSavePostProcessingEnabled": false,
            "ForceCheckout": false,
            "HasExternalDataSource": false,
            "Hidden": true,
            "Id": "sample-id",
            "IrmEnabled": false,
            "IrmExpire": false,
            "IrmReject": false,
            "IsApplicationList": false,
            "IsCatalog": false,
            "IsPrivate": false,
            "ItemCount": 1,
            "LastItemDeletedDate": "2015-05-19T11:13:46Z",
            "LastItemModifiedDate": "2015-08-04T06:57:22Z",
            "ListItemEntityTypeFullName": "SP.Data.AccessRequestsItem",
            "MajorVersionLimit": 0,
            "MajorWithMinorVersionsLimit": 0,
            "MultipleDataList": false,
            "NoCrawl": true,
            "ParentWebUrl": "/",
            "ParserDisabled": false,
            "ServerTemplateCanCreateFolders": true,
            "TemplateFeatureId: "sample-id",
            "Title": "Test Title"
        }, {
        ........
    }]
}

在上述回复中,我得到了与 Sharepoint System 相关的字段以及我想要的字段。 例如:odata.typeodata.idAllowContentTypesBaseTemplate

我如何获得我需要的字段,而不是其他与 Sharepoint 相关的字段。

有人可以帮忙吗?

谢谢

【问题讨论】:

  • 你为什么打电话给/_api/$metadata#SP.ApiData.Lists而不是/_api/web/lists
  • 我只打电话给/_api/web/lists。它给了我上面粘贴的回复。

标签: node.js sharepoint odata


【解决方案1】:

为此,您可以使用$select 查询选项(关注OData Version 2.0 了解更多详情)。

关于 odata.typeodata.id 属性,因为它们是一部分 元数据属性,你只需要指定正确的Accept 标头以请求它们(例如:accept: application/json;odata=minimalmetadata)。更多详情请关注JSON Light support in REST SharePoint API released 文章。

以下示例返回一组特定的 List 资源属性,例如 AllowContentTypesBaseTemplate

Endpoint URI: https://contoso.sharepoint.com/_api/web/lists?$select=AllowContentTypes,BaseTemplate 
Accept: application/json; odata=minimalmetadata
Method: GET

结果

{
    "d": {
        "results": [
            {
                "__metadata": {
                    "id": "https://contoso.sharepoint.com/_api/Web/Lists(guid'82dcfcc5-e58c-4610-b4c3-589a7228e912')",
                    "uri": "https://contoso.sharepoint.com/_api/Web/Lists(guid'82dcfcc5-e58c-4610-b4c3-589a7228e912')",
                    "etag": "\"0\"",
                    "type": "SP.List"
                },
                "AllowContentTypes": true,
                "BaseTemplate": 125
            },
            //...
        ]
    }
}

【讨论】:

  • 我只想在响应中获取用户特定的字段,而不是 Sharepoint 特定的字段
  • 您能否详细说明一下,什么是“用户特定字段”和“Sharepoint 特定字段”?
  • 此外,从我的回答中是否可以看出如何检索odata.type, odata.id, AllowContentTypes, BaseTemplate 属性?
  • 实际上我正在尝试将 Sharepoint REST API 端点动态映射到 expressjs 路由。在这种情况下,我不知道用户想要拥有哪些字段。所以在 URL 中我将无法使用 $select 。
猜你喜欢
  • 2015-03-03
  • 2011-02-13
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
  • 2016-01-26
  • 2017-11-01
  • 2016-10-20
  • 2023-03-29
相关资源
最近更新 更多