the shared with me api does not work, why?

Nikola Zdravevski 120 Reputation points
2025-11-10T10:45:24.5333333+00:00

The shared with me api call to one drive does not return the relevant data, I get only one item every time I run the query even though I have proper token and more items to show

Developer technologies | XAML
Developer technologies | XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
{count} votes

3 answers

Sort by: Most helpful
  1. Scott Rudy 41 Reputation points
    2025-11-15T01:26:48.5566667+00:00

    It's definitely broken. That said I found a way to use the search API to get the item, but it's still a mess, IMHO. In my case I am used a shared folder in the same tenant, so if using a remote item your mileage may vary. Note the DriveItem isn't a folder type anymore.

    Old (Broken) Code:

    var drives = await _graphClient!.Me.Drive.GetAsync(config =>
    	config.QueryParameters.Select = ["id"]);
    
    var children = (await 
    	_graphClient.Drives[drives!.Id].SharedWithMe.GetAsSharedWithMeGetResponseAsync(config =>
    	{
    		config.QueryParameters.Select = ["id", "Name", "Folder", "remoteItem"];
    	}))?.Value;
    
    var item = children?.FirstOrDefault(i => i.Folder != null && i.Name == folderName);
    
    if (item == null) return;
    
    var remoteDriveId = item!.RemoteItem?.ParentReference?.DriveId;
    var folderItems = (await
        _graphClient.Drives[remoteDriveId].Items[item.Id].Children.GetAsync(
    	{
    		config.QueryParameters.Orderby = ["lastModifiedDateTime desc"];
    		config.QueryParameters.Select = ["id", "name", "lastModifiedDateTime"];
        }))?.Value;
    

    New (Working) Code:

    var searchResponse = await _graphClient!.Search.Query.PostAsQueryPostResponseAsync(
        new Microsoft.Graph.Search.Query.QueryPostRequestBody
    {
        Requests =
        [
            new Microsoft.Graph.Models.SearchRequest
            {
                EntityTypes = [Microsoft.Graph.Models.EntityType.DriveItem],
                Query = new Microsoft.Graph.Models.SearchQuery
                { 
                    QueryString = $"{folderName}", QueryTemplate = "FileName:{searchTerms}"
                },
                Fields = ["Id","ParentReference"],
                Size = 1 // Assumes I know what I'm doing here
            }
        ]
    });
    
    if (searchResponse?.Value?[0]?.HitsContainers?[0]?.Hits?.SingleOrDefault()?.Resource is not Microsoft.Graph.Models.DriveItem item) return;
    
    var remoteDriveId = item!.ParentReference?.DriveId;
    var folderItems = (await
        _graphClient.Drives[remoteDriveId].Items[item.Id].Children.GetAsync(config =>
        {
            config.QueryParameters.Orderby = ["lastModifiedDateTime desc"];
            config.QueryParameters.Select = ["id", "name", "lastModifiedDateTime"];
        }))?.Value;
    
    
    1 person found this answer helpful.

  2. Raymond Huynh (WICLOUD CORPORATION) 3,975 Reputation points Microsoft External Staff Moderator
    2025-11-11T11:08:36.03+00:00

    Hi Nikola Zdravevski ,

    Please note that the sharedWithMe API only shows files that other people have actually shared with you, not files you've shared with them.

    Try this link instead to see files you've shared: https://graph.microsoft.com/v1.0/me/drive/shared

    If that works and shows your files, then the API is actually working correctly. You just might not have files that others have shared with you yet.

    Please also check the document below:

    https://v4.hkg1.meaqua.org/en-us/graph/api/drive-sharedwithme

     

    Please tell me if you still encounter this issue!


  3. kbu 5 Reputation points
    2025-11-17T18:24:03.37+00:00

    A workaround could be to directly use the Sharepoint API like this:

    https://johndoe-my.sharepoint.com/_api/v2.0/drive/oneDrive.sharedWithMe


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.