Failing to retrieve items programmatically from a drive, in a sharepoint site

VANBESIEN, MAXENCE 0 Reputation points
2025-09-05T15:51:40.3233333+00:00

Failing to retrieve items programmatically from a drive, in a sharepoint site

I'm using the Microsoft GraphAPI Java framework (version 6.51.0), to try to download a file, programmatically, from a SharePoint site.

I have the ID of the site, and from it, I manage to iterate all the drives from this site, to get their ID. I manage to get names, id and path successfully

Now, I try to retrieve the content of a given drive, and anything I try, returns me something OK trying to access the drive, but the following error even trying to access the root of the drive I'd like to process :

com.microsoft.graph.models.odataerrors.ODataError: The resource could not be found from code DriveItem driveItem = graphClient.drives().byDriveId(drive.getId()).root().get();

My admin team confirmed that I have access to the full drive, but still this error still pops us whether I'm trying to access the root of the drive or any file that I can see, on SharePoint, in this drive...

Any hint on what I should investigate to try to get this access ?

(Note that on the UI, I can only access the drive contents in the "Classic Experience" mode... And when trying to "exit classic experience" nothing happens, meaning that the drive might be the result of a migration from an older version. Do you think this might be a reason why the API fails to access any file from the drive ?)

Thanks !

Microsoft 365 and Office | SharePoint | For business | Android

2 answers

Sort by: Most helpful
  1. VANBESIEN, MAXENCE 0 Reputation points
    2025-09-08T09:44:15.14+00:00

    Dear,

    Thanks for the quick answer and the hints ! I've indeed investigated with the lists instead of the drives, and strangely, I reach a situation similar as with the drives...

    At first, I tried programmatically, by using
    List spList = graphClient.sites().bySiteId(spSiteID).lists().byListId(listID).get();

    Here, I indeed get a list object, with creation date, ID, etc... But when trying to get a drive() or the items(), it always returns "null", so not possible to browse...

    I tried with the URL approach (which cannot be the target as I need to use here a client id, etc..., And the https://<tenant>.sharepoint.com/sites/<site>/_api/web/Lists/getByTitle('Reporting')/items returns relevant data.

    I have raised the point to our admin team for checking the rights, which is what I would see as an issue and if confirmed, I will close this request. Otherwise, I will let you know we would need more help

    Was this answer helpful?


  2. Kai-L 19,145 Reputation points Microsoft External Staff Moderator
    2025-09-05T17:15:00.2533333+00:00

    Dear @VANBESIEN, MAXENCE,

    Thank you for reaching out to the Microsoft Q&A Community.

    From my research, the ODataError: The resource could not be found message you're seeing is puzzling, especially since your admin confirmed full access. This error can occur for several reasons and may be related to how the API is configured to interact with your site's content. Your observation about the "Classic Experience" mode is a very interesting lead.

    Here are some areas we can investigate to help diagnose and resolve this issue.

     

    Permissions and Scopes

    Even though your admin team confirmed you have access to the full drive, the Graph API requires specific permissions (scopes) that might not be correctly configured for your application.

    To read drive items, your application needs the Sites.Read.All or Files.Read.All permission. For sites with classic libraries, the Sites.Read.All permission is generally what you want. Confirm with your admin that your application's service principal or your user account has these exact permissions granted.
    User's image

    For reference: Microsoft Graph permissions reference - Microsoft Graph | Microsoft Learn

     

    Potential API Endpoint Behavior

    The drives() endpoint is designed to work seamlessly with modern SharePoint document libraries. However, it's possible that a site in "Classic Experience" mode may not expose its resources to the API in the same way.

    As a diagnostic step, you could try using a more direct, SharePoint-specific API endpoint to access the library. This approach may help determine if the issue is with the drive's abstraction or with the resource itself.

    Instead of /drives/{drive-id}/root, you could try a path like this:

    [https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/drive/root]

    To do this, you would first need to get the list-id of the document library. You can find this by retrieving a list of all lists for a given site.

    For references:
    Working with SharePoint sites in Microsoft Graph - Microsoft Graph v1.0 | Microsoft Learn
    Get a SharePoint Site - Microsoft Graph v1.0 | Microsoft Learn

     

    You can find answer similar to your question here : How to Form URL to Fetch Items From a Sharepoint List via Graph API? - Stack Overflow (Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link)

     

    If none of the above solutions work, let me know for further investigation. Please note that our initial response does not always resolve the issue immediately. However, with your help and more detailed information, we can work together to find a solution. Thank you for your patience and understanding. 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    User's image

    Was this answer helpful?

    0 comments No comments

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.