List deletedItems (directory objects)

Namespace: microsoft.graph

Retrieve a list of recently deleted directory objects. Currently, deleted items functionality is only supported for the application, servicePrincipal, group, and user resources.

Note: Deleted security groups are deleted permanently and can't be retrieved through this API.

Permissions

When an application queries a relationship that returns a directoryObject type collection, if it does not have permission to read a certain derived type (like device), members of that type are returned but with limited information. With this behaviour applications can request the least privileged permissions they need, rather than rely on the set of Directory.* permissions. For details, see Limited information returned for inaccessible member objects.

One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

For applications and service principals:

Permission type Permissions (from least to most privileged)
Delegated (work or school account) Application.Read.All, Application.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All
Delegated (personal Microsoft account) Not supported.
Application Application.Read.All, Application.ReadWrite.All, Directory.Read.All

For users:

Permission type Permissions (from least to most privileged)
Delegated (work or school account) User.Read.All, User.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All
Delegated (personal Microsoft account) Not supported.
Application User.Read.All, User.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All

For groups:

Permission type Permissions (from least to most privileged)
Delegated (work or school account) Group.Read.All, Group.ReadWrite.All, Directory.Read.All
Delegated (personal Microsoft account) Not supported.
Application Group.Read.All, Group.ReadWrite.All, Directory.Read.All

HTTP request

GET /directory/deleteditems/microsoft.graph.application
GET /directory/deleteditems/microsoft.graph.servicePrincipal
GET /directory/deletedItems/microsoft.graph.group
GET /directory/deletedItems/microsoft.graph.user
GET /directory/deletedItems/microsoft.graph.device

This API currently supports retrieving object types of applications (microsoft.graph.application), servicePrincipals (microsoft.graph.serviceprincipal), groups (microsoft.graph.group), or users (microsoft.graph.user) from deleted items. The OData cast type is a required part of the URI and calling GET /directory/deleteditems without a type is not supported.

Optional query parameters

This method supports the query parameters that are supported by the resource that is specified by the OData cast. That is, $count, $expand, $filter, $orderBy, $search, $select, and $top query parameters. Some queries are supported only when you use the ConsistencyLevel header set to eventual and $count. For example:

GET https://graph.microsoft.com/beta/directory/deletedItems/microsoft.graph.group?&$count=true&$orderBy=deletedDateTime desc&$select=id,displayName,deletedDateTime
ConsistencyLevel: eventual

This example requires the ConsistencyLevel header because the $orderBy and $count query parameters are used in the query.

Examples using the $orderBy OData query parameter

The $orderBy OData query parameter is supported on the deletedDateTime, displayName, and userPrincipalName properties of the deleted object types. On the deletedDateTime property, the query requires adding the advanced query parameters (ConsistencyLevel header set to true and $count=true query string).

OData cast Properties supporting $orderBy Example
microsoft.graph.user deletedDateTime, displayName, userPrincipalName /directory/deletedItems/microsoft.graph.user?$orderBy=userPrincipalName
microsoft.graph.group deletedDateTime, displayName /directory/deletedItems/microsoft.graph.group?$orderBy=deletedDateTime asc&$count=true
microsoft.graph.application deletedDateTime, displayName /directory/deletedItems/microsoft.graph.application?$orderBy=displayName
microsoft.graph.device deletedDateTime, displayName /directory/deletedItems/microsoft.graph.device?$orderBy=deletedDateTime&$count=true

Request headers

Name Description
Authorization Bearer <code> Required
Accept application/json

Request body

Do not supply a request body for this method.

Response

If successful, this method returns a 200 OK response code and collection of directoryObject objects in the response body.

Examples

Example 1: Retrieve deleted groups

Request

GET https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.group

Response

Note: The response object shown here might be shortened for readability.

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

{
  "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups",
  "value": [
    {
      "id":"46cc6179-19d0-473e-97ad-6ff84347bbbb",
      "displayName":"SampleGroup",
      "groupTypes":["Unified"],
      "mail":"example@contoso.com",
      "mailEnabled":true,
      "mailNickname":"Example",
      "securityEnabled":false,
      "visibility":"Public"
    }
  ]
}

Example 2: Retrieve the count of deleted user objects and order the results by the deletedDateTime property

Request

GET https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.group?$count=true&$orderBy=deletedDateTime asc&$select=id,DisplayName,deletedDateTime
ConsistencyLevel: eventual

Response

Note: The response object shown here might be shortened for readability.

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

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups(id,displayName,deletedDateTime)",
    "@odata.count": 2,
    "value": [
        {
            "id": "c31799b8-0683-4d70-9e91-e032c89d3035",
            "displayName": "Role assignable group",
            "deletedDateTime": "2021-10-26T16:56:36Z"
        },
        {
            "id": "74e45ce0-a52a-4766-976c-7201b0f99370",
            "displayName": "Role assignable group",
            "deletedDateTime": "2021-10-26T16:58:37Z"
        }
    ]
}