directoryObject: delta

命名空间: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 不支持
appRoleAssignment User.Read.All User.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.appRoleAssignment') or isof('microsoft.graph.user')
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')

跟踪目录对象的更改。 资源不支持此请求 appRoleAssignment 。

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:

    • 这表示会话中要检索的数据页更多。 应用程序继续使用 URL 发出请求, @odata.nextLink 直到 @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 请求中。 标头仅影响响应中包含的属性集,不会影响增量查询的执行方式。 请参阅 示例 4。

示例

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

请求

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

GET https://graph.microsoft.com/v1.0/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/v1.0/$metadata#directoryObjects","@odata.nextLink":"https://graph.microsoft.com/v1.0/directoryObjects/delta?$skiptoken=pqwSUjGYvb3jQpbwVAwEL7yuI3dU1LecfkkfLPtnIjvY1FSSc_",
  "value":[
    {
      "@odata.type": "#microsoft.graph.user",
      "displayName": "Adele Vance",
      "givenName": "Adele",
      "jobTitle": "Retail Manager",
      "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/v1.0/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/v1.0/$metadata#directoryObjects",
  "@odata.nextLink":"https://graph.microsoft.com/v1.0/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/v1.0/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/v1.0/$metadata#directoryObjects",
  "@odata.nextLink":"https://graph.microsoft.com/v1.0/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/v1.0/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/v1.0/$metadata#directoryObjects",
  "@odata.nextLink":"https://graph.microsoft.com/v1.0/directoryObjects/delta?$skiptoken=pqwSUjGYvb3jQpbwVAwEL7yuI3dU1LecfkkfLPtnIjsXoYQp_dpA3cNJWc",
  "value": [
    {
      "@odata.type": "#microsoft.graph.group",
      "displayName":"Everyone",
      "id": "72052a9a-c466-4995-8210-95a1c1221995",
    }
  ]
}