Yan Lin
Yan Lin

Reputation: 43

Cannot Access DeletedItems through Microsoft.Graph

I try to access the DeletedItems via Microsoft Graph.

Here is my code:

graphClient
  .Directory
  .DeletedItems[userid]
  .Request()
  .GetAsync();

I receive this exception response:

Code: BadRequest. 
Message: Resource not found for the segment 'directory'. 

Anyone knows how to access deletedItems correctly? Am I missing something to access it?

Upvotes: 2

Views: 417

Answers (1)

Darrel Miller
Darrel Miller

Reputation: 142094

This particular call is a little unusual in that the Id that is used is not actually the user Id, but is object type or objectId. So to get a list of deleted items, you pass the type in the array index.

e.g.

var graphClient = new GraphServiceClient(null);

var request = graphClient
      .Directory
      .DeletedItems["microsoft.graph.user"]
      .Request()
      .GetHttpRequestMessage();

var content = new HttpMessageContent(request);
Console.Write(content.ReadAsStringAsync().Result);
Console.Read();


Output:

GET /v1.0/directory/deletedItems/microsoft.graph.user HTTP/1.1
Host: graph.microsoft.com
SdkVersion: Graph-dotnet-1.13.0

The above code demonstrates a handy way of seeing exactly what HTTP request the library is attempting to send. It requires pulling in the Microsoft.AspNet.WebApi.Client Nuget to get the HttpMessageContent object.

Upvotes: 4

Related Questions