Search code examples
.net-coreweb-applicationsmicrosoft-graph-apimicrosoft-graph-sdksmicrosoft-graph-files

Calling Microsoft graph API from dotnetcore app returns NotFound


I'm trying to get items from SharePoint using the Graph API in the name of the user, all these done inside a .net core 3.1 web app using oauth. When I request for specific items in a SharePoint document library I get the following ServiceException:

ex = {"Code: itemNotFound\r\nMessage: The resource could not be found.\r\nInner error:\r\n\tAdditionalData:\r\n\trequest-id: 7605d475-5967-481e-a16c-ab1fad610ef9\r\n\tdate: 2020-04-15T21:27:48\r\nClientRequestId: 7605d475-5967-481e-a16c-ab1fad610ef9\r\n"}

My calling function is the following:

var searchResult = await graphServiceClient
                    .Sites[$"{SharePointSiteId}"]
                    .Drives[$"{SharePointDocumentLibraryId}"]
                    .Items[$"{InvoicesFolderId}"]
                    .Children
                    .Request()
                    .GetAsync();

where:

  • SharePointSiteId is a fully qualified SPS site Id
  • SharePointDocumentLibraryId id of the document library
  • InvoicesFolderId id of the folder in which I'd like to enumerate the children elements

The strange is that until I request for the Drive only:

var searchResult = await graphServiceClient
                    .Sites[$"{SharePointSiteId}"]
                    .Drives[$"{SharePointDocumentLibraryId}"]
                    .Request()
                    .GetAsync();

everything goes fine.

Strange thing 2: If I call the API using the Graph explorer with the same user in the same time using the Item identifier {InvoicesFolderId}, it gives back its children well. Needless to say, the user can login to the SPS site and do whatever she wants. :)


Solution

  • I am able to reproduce the same exception thrown when calling from Graph .Net SDK in C#. Taking the exact same URL that is generated by SDK and testing in Graph Explorer is successful as well. I would recommend opening an issue on the Graph .Net SDK repo.