directoryObject: 增量

重要

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

命名空间:microsoft.graph

获取新创建、更新或删除的目录对象,而无需完全读取整个 directoryObject 集合。 有关详细信息,请参阅 使用增量查询跟踪 Microsoft Graph 数据中的更改 。

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

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

权限

下表显示了调用此 API 时每种资源类型所需的最低特权权限。 若要了解详细信息,包括如何选择权限的信息,请参阅权限。

支持的资源 委派(工作或学校帐户) 应用程序 委派(个人 Microsoft 帐户)
application Application.Read.All Application.Read.All 不支持
administrativeUnit AdministrativeUnit.Read.All AdministrativeUnit.Read.All 不支持
设备 Device.Read.All Device.Read.All 不支持
directoryRole RoleManagement.Read.Directory RoleManagement.Read.Directory 不支持
组 Group.Read.All Group.Read.All 不支持
orgContact OrgContact.Read.All OrgContact.Read.All 不支持
servicePrincipal Application.Read.All Application.Read.All 不支持
user User.Read.All User.Read.All 不支持

HTTP 请求

跟踪目录对象类型集合的更改。

GET /directoryObjects/delta?$filter=isof('microsoft.graph.application')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.administrativeUnit')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.device')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.directoryRole')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.group')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.orgContact')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.servicePrincipal')
GET /directoryObjects/delta?$filter=isof('microsoft.graph.user')

跟踪目录对象的更改。

GET /directoryObjects/delta?$filter=id eq '{id}'

OData 查询参数

此方法支持可选的 OData 查询参数,以帮助自定义响应。

  • 像在任何 GET 请求中一样,你可以使用 $select 查询参数以仅指定获取最佳性能所需的属性。 始终返回 id 属性。
  • 例如,筛选多个对象时, /directoryObjects/delta/?$filter=id eq '477e9fc6-5de7-4406-bb2a-7e5c83c9ffff' or id eq '004d6a07-fe70-4b92-add5-e6e37b8affff'筛选表达式限制为 50 个。
  • 可以组合语 $filter 法。 例如,$filter=isof('{resource type}') or id eq '{id}'。 这提供了由匹配{resource type}指定的对象和资源类型 {id}.

请求标头

名称 说明
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权。
Content-Type application/json
Prefer return=minimal

在使用 @odata.deltaLink 的请求中执行此标头将仅返回自上一轮之后发生更改的对象属性。 可选。

请求正文

请勿提供此方法的请求正文。

响应

如果成功,此方法将在响应正文中返回 200 OK 响应代码和 directoryObject 集合对象。 响应还包括状态 @odata.nextLink 令牌(URL 或 @odata.deltaLink URL)。

  • 如果返回 @odata.nextLinkURL:

    • 这表示在会话中要检索的数据页更多。 应用程序将继续使用 @odata.nextLink URL 发出请求,直到 @odata.deltaLink 响应中包含 URL。
    • 响应包含与初始 Delta 查询请求相同的属性集。 这使你能够在发起 Delta 循环时捕获对象当前的完整状态。
  • 如果返回 @odata.deltaLinkURL:

    • 这表示没有关于要返回的资源的现有状态的更多数据。 保存并使用 @odata.deltaLink URL 来了解下一轮资源更改。
    • 只有对于在签发 @odata.deltaLink 之后更改的属性,你才可以选择指定 Prefer:return=minimal 标头以包含在响应值中。

默认:返回与初始 Delta 请求相同的属性

默认情况下,使用 @odata.deltaLink 或 @odata.nextLink 的请求将通过以下方式返回与初始 Delta 查询中选择的相同属性:

  • 如果属性已更改,则新值将包括在响应中。 这包括设为 Null 值的属性。
  • 如果属性未更改,则响应中将包含旧值。
  • 如果之前从未设置属性,则它不会包括在响应中。

注意:如果出现此行为,那么通过查看响应无法区分属性是否已更改。 此外,增量响应往往较大,因为它们包含所有属性值 - 如 示例 3 所示。

备用:仅返回更改的属性

添加可选请求标头 - prefer:return=minimal - 将导致出现以下行为:

  • 如果属性已更改,则新值将包括在响应中。 这包括设为 Null 值的属性。
  • 如果属性未更改,则响应中根本不包含该属性。 (不同于默认行为。)

注意:可以在 Delta 循环中的任何时间点将标头添加到 @odata.deltaLink 请求中。 标头仅影响响应中包含的属性集,不会影响增量查询的执行方式。 请参阅

示例

示例 1:检索用户和组集合的更改

请求

下面的示例演示了在用户和组上使用参数的 $filter=isof('{resource type}') 请求。 没有 $select 参数,因此会跟踪并返回一组默认属性。

GET https://graph.microsoft.com/beta/directoryObjects/delta?filter=isof('microsoft.graph.user') or isof('microsoft.graph.group')

响应

下面的示例显示了使用 @odata.deltaLink 从 $filter=isof('{resource type}')查询初始化中获取的响应。 请注意,包含组中成员对象 ID 的 members@delta 属性的存在。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

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

{
  "@odata.context":"https://graph.microsoft.com/beta/$metadata#directoryObjects","@odata.nextLink":"https://graph.microsoft.com/beta/directoryObjects/delta?$skiptoken=pqwSUjGYvb3jQpbwVAwEL7yuI3dU1LecfkkfLPtnIjvY1FSSc_",
  "value":[
    {
      "@odata.type": "#microsoft.graph.user",
      "businessPhones": [
          "+1 425 555 0109"
      ],
      "displayName": "Adele Vance",
      "givenName": "Adele",
      "jobTitle": "Retail Manager",
      "mail": "AdeleV@contoso.com",
      "mobilePhone": "+1 425 555 0109",
      "officeLocation": "18/2111",
      "preferredLanguage": "en-US",
      "surname": "Vance",
      "userPrincipalName": "AdeleV@contoso.com",
      "id": "87d349ed-44d7-43e1-9a83-5f2406dee5bd"
    },
    {
      "@odata.type": "#microsoft.graph.group",
      "createdDateTime":"2021-03-12T10:36:14Z",
      "description":"This is the default group for everyone in the network",
      "displayName":"All Company",
      "groupTypes": [
        "Unified"
      ],
      "mail": "allcompany@contoso.com",
      "id": "72052a9a-c466-4995-8210-95a1c1221995",
      "members@delta": [
        {
          "@odata.type": "#microsoft.graph.user",
          "id": "693acd06-2877-4339-8ade-b704261fe7a0"
        },
        {
          "@odata.type": "#microsoft.graph.user",
          "id": "49320844-be99-4164-8167-87ff5d047ace"
        }
      ]
    }
  ]
}

示例 2:检索目录对象的更改集合

请求

下面的示例演示了使用参数 $filter=id eq '{id}' 的请求。 没有 $select 参数,因此会跟踪并返回一组默认属性。

GET https://graph.microsoft.com/beta/directoryObjects/delta?$filter=id eq '87d349ed-44d7-43e1-9a83-5f2406dee5bd'

响应

下面的示例显示了使用 @odata.deltaLink 从 $filter=id eq '{id}'查询初始化中获取的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

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

{
  "@odata.context":"https://graph.microsoft.com/beta/$metadata#directoryObjects",
  "@odata.nextLink":"https://graph.microsoft.com/beta/directoryObjects/delta?$skiptoken=pqwSUjGYvb3jQpbwVAwEL7yuI3dU1LecfkkfLPtnIjsXoYQp_dpA3cNJWc",
  "value": [
    {
      "@odata.type": "#microsoft.graph.group",
      "createdDateTime":"2021-03-12T10:36:14Z",
      "description":"This is the default group for everyone in the network",
      "displayName":"All Company",
      "groupTypes": [
        "Unified"
      ],
      "mail": "allcompany@contoso.com",
      "id": "72052a9a-c466-4995-8210-95a1c1221995",
      "members@delta": [
        {
          "@odata.type": "#microsoft.graph.user",
          "id": "693acd06-2877-4339-8ade-b704261fe7a0"
        },
        {
          "@odata.type": "#microsoft.graph.user",
          "id": "49320844-be99-4164-8167-87ff5d047ace"
        }
      ]
    }
  ]
}

示例 3:检索对用户和组集合的特定属性的更改

请求

以下示例显示了从用户和组中各选择一个属性以进行更改跟踪的初始请求,具有默认响应行为:

GET https://graph.microsoft.com/beta/directoryObjects/delta?$filter=isof('microsoft.graph.user') or isof('microsoft.graph.group')&$select=microsoft.graph.user/surname,microsoft.graph.group/displayName

响应

下面的示例显示了使用 @odata.deltaLink 从查询初始化中获取时的响应。 这两个属性都包含在响应中,不知道自获取以来 @odata.deltaLink 哪些属性发生了变化。

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

{
  "@odata.context":"https://graph.microsoft.com/beta/$metadata#directoryObjects",
  "@odata.nextLink":"https://graph.microsoft.com/beta/directoryObjects/delta?$skiptoken=pqwSUjGYvb3jQpbwVAwEL7yuI3dU1LecfkkfLPtnIjsXoYQp_dpA3cNJWc",
  "value": [
    {
      "@odata.type": "#microsoft.graph.user",
      "surname": "Vance",
      "id": "87d349ed-44d7-43e1-9a83-5f2406dee5bd"
    },
    {
      "@odata.type": "#microsoft.graph.group",
      "displayName":"All Company",
      "id": "72052a9a-c466-4995-8210-95a1c1221995",
    }
  ]
}

示例 4:仅当特定属性针对用户和组集合更改时才检索这些属性

请求

下面的示例显示了初始请求从用户和组中各选择一个属性进行更改跟踪,以及备用的最小响应行为:

GET https://graph.microsoft.com/beta/directoryObjects/delta?$filter=isof('microsoft.graph.user') or isof('microsoft.graph.group')&$select=microsoft.graph.user/surname,microsoft.graph.group/displayName
Prefer: return=minimal

响应

下面的示例显示了使用 @odata.deltaLink 从查询初始化中获取时的响应。 不包括属性 microsoft.graph.user/surname ,这意味着自上次增量查询以来它没有变化; microsoft.graph.group/displayName 包括在内,意味着它的值已更改。

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

{
  "@odata.context":"https://graph.microsoft.com/beta/$metadata#directoryObjects",
  "@odata.nextLink":"https://graph.microsoft.com/beta/directoryObjects/delta?$skiptoken=pqwSUjGYvb3jQpbwVAwEL7yuI3dU1LecfkkfLPtnIjsXoYQp_dpA3cNJWc",
  "value": [
    {
      "@odata.type": "#microsoft.graph.group",
      "displayName":"Everyone",
      "id": "72052a9a-c466-4995-8210-95a1c1221995",
    }
  ]
}