How can I access a shared Sharepoint folder from GraphSDK?

Anderson 0 Reputation points
2026-08-07T19:22:42.6766667+00:00

Hi!

So, I'm tasked with implementing a java code (for a web application) that will update some files on sharepoint when the user updates some data.

I have been given access to a folder "https://companyname.sharepoint.com/sites/departmentname/path/to/folder", when it was shared with me, but, otherwise, I don't have much access to the other department's sharepoint.

I have added my application to EntraID with scopes "User.Read" and "Files.SelectedOperations.Selected".

I was able to login and read some graphCliente.me() information. But, so far, I can't figure out how to read the sharepoint folder I'm supposed to manage.

A lot of what I've found says I should provide the driveId for the request. But I can't seem to find it with the level of access I have now.

I have tried adding the permission request from https://learn.microsoft.com/en-us/graph/permissions-selected-overview?tabs=java. But it doesn't work: "Access denied".

I've also tried to adapt it by changing the request line to include a getByPathWithPath("path/to/folder"), but still no luck. (Fails with a 400 Bad Request.)

Permission result = graphClient.sites().bySiteId("{site-id}").getByPathWithPath("path/to/folder").permissions().post(permission);

Does anyone know what's missing/wrong here?

Also, I there was a way to log complete requests/responses, that might help.

Thanks.

And sorry, if this is a dumb question, but I'm not used to MS-specific stuff, and this all still seems a bit confusing.

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Oldest
  1. Azizkhon Ishankhonov 1,015 Reputation points
    2026-09-07T19:14:24.5166667+00:00

    I recommend starting with Graph Explorer to test and construct your API requests before implementing them in your Java application.
    Also, you can find sample code in Java in code snippet section.

    To access the target site, drive, and folder items, follow these steps:

    • Get Site ID

    Retrieve your site details using the hostname and relative path:

    GET /sites/{hostname}:/sites/{departmentname}

    • Get Document Libraries (Drives)

    List all drives under the site to locate your target drive-id:

    GET /sites/{site-id}/drives

    • Access Specific Folder or Item

    Access items using the drive ID and folder path:

    GET /drives/{drive-id}/root:/path/to/folder:/children

    Permission Note: Ensure your application registration has the necessary delegated or application permissions (such as Files.ReadWrite.All or Sites.Selected configured with appropriate site access) if accessing items outside the standard user context.

    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.