获取列表的元数据

命名空间:microsoft.graph

重要

Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

返回 列表的元数据。

此 API 可用于以下国家级云部署。

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国
✅ ✅ ✅ ✅

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) Sites.Read.All Sites.ReadWrite.All
委派(个人 Microsoft 帐户) 不支持。 不支持。
应用程序 Sites.Read.All Sites.ReadWrite.All

HTTP 请求

GET /sites/{site-id}/lists/{list-id}
GET /sites/{site-id}/lists/{list-title}
GET /sites/{site-id}/lists/{list-id}?expand=columns,items(expand=fields)

请求正文

请勿使用此方法提供请求正文。

示例

示例 1:按 ID 获取列表元数据

以下示例演示如何获取 SharePoint 列表的元数据。

请求

下面的示例演示了一个请求。

GET /sites/{site-id}/lists/{list-id}

响应

下面的示例演示了响应。

HTTP/1.1 200 OK
Content-type: application/json

{
  "id": "1234-112-112-4",
  "name": "MicroFeed",
  "createdDateTime": "2016-08-30T08:32:00Z",
  "lastModifiedDateTime": "2016-08-30T08:32:00Z",
  "itemCount": 127,
  "list": {
    "hidden": false,
    "template": "genericList"
    }
}

示例 2:按标题获取列表元数据

下面示例演示如何从 SharePoint Online 列表标题获取列表。

请求

以下示例显示了一个请求。

GET /sites/{site-id}/lists/{list-title}

响应

以下示例显示了相应的响应。

HTTP/1.1 200 OK
Content-type: application/json

{
  "id": "1234-112-112-4",
  "name": "MicroFeed",
  "createdDateTime": "2016-08-30T08:32:00Z",
  "lastModifiedDateTime": "2016-08-30T08:32:00Z",
  "itemCount": 45,
  "list": {
    "hidden": false,
    "template": "genericList"
    }
}

示例 3:使用 $select 和 $expand 获取列表元数据和项

下面的示例演示如何使用 $select$expand 和 OData 查询参数在单个请求中检索列表元数据、列定义和列表项。

请求

以下示例显示了一个请求。

GET /sites/{site-id}/lists/{list-id}?select=name,lastModifiedDateTime,itemCount&expand=columns(select=name,description),items(expand=fields(select=Name,Color,Quantity))

响应

以下示例显示了相应的响应。

HTTP/1.1 200 OK
Content-type: application/json

{
  "name": "Inventory",
  "lastModifiedDateTime": "2016-08-30T08:32:00Z",
  "columns": [
    {
      "name": "Name",
      "description": "Customer-facing name of the SKU"
    },
    {
      "name": "Color",
      "description": "Color of the item in stock"
    },
    {
      "name": "Quantity",
      "description": "Number of items in stock"
    }
  ],
  "items": [
    {
      "id": "2",
      "fields": {
        "Name": "Gadget",
        "Color": "Red",
        "Quantity": 503
       }
    },
    {
      "id": "4",
      "fields": {
        "Name": "Widget",
        "Color": "Blue",
        "Quantity": 2357
       }
    },
    {
      "id": "7",
      "fields": {
        "Name": "Gizmo",
        "Color": "Green",
        "Quantity": 92
       }
    }
  ],
  "itemCount": 45
}

示例 4:获取具有多个$expand参数的列表元数据和项

以下示例演示如何获取包含三列的列表的元数据和项目: 名称、 数量和 类别。 托管元数据 列,如 Category 将值返回为术语 ID 和术语名称对。

请求

以下示例显示了一个请求。

GET /sites/{site-id}/lists/{list-id}?select=name,lastModifiedDateTime&expand=columns(select=name,description),items(expand=fields(select=Name,Quantity,Category))

响应

以下示例显示了相应的响应。

HTTP/1.1 200 OK
Content-type: application/json

{
  "name": "Inventory",
  "lastModifiedDateTime": "2016-08-30T08:32:00Z",
  "columns": [
    {
      "name": "Name",
      "description": "Customer-facing name of the SKU"
    },
    {
      "name": "Quantity",
      "description": "Number of items in stock"
    },
    {
      "name": "Category",
      "description": "Category of the item"
    }
  ],
  "items": [
    {
      "id": "2",
      "fields": {
        "Name": "Gadget",
        "Quantity": 503,
        "Category": {
          "termId": "791d537a-9c1c-3b05-97b0-1ce7ece7e1a4",
          "name": "Tool"
         }
       }
    },
    {
      "id": "4",
      "fields": {
        "Name": "Widget",
        "Quantity": 2357,
        "Category": {
          "termId": "902e568b-9b2d-4d06-87c2-2cf8ecf9f2b5" ,
          "name": "Mechanical Device"
         }
       }
    }
  ]
}