Hello Amol Harde,
Thanks for reaching out!
To list user drives:
GET https://graph.microsoft.com/v1.0/users/48d31887-5fad-4d73-a9f5-3c356e68a038/drives
Java Code Snippet:
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
DriveCollectionPage drives = graphClient.users("48d31887-5fad-4d73-a9f5-3c356e68a038").drives()
.buildRequest()
.get();
To list children in the root of the current user's drive: This will list all the items (folders and files) along with the Item-IDs present in drive at root level.
GET /me/drive/root/children
Java Code Snippet:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var children = await graphClient.Me.Drive.Root.Children
.Request()
.GetAsync();
To list children of a DriveItem with a known ID: This will list all the sub-items (folders and files) along with the Item-IDs inside a driveItem (folder).
Please note that every item-id is either a file ID or folder ID. The response will have id, name of items and other details. You can identify whether an item is a folder or a file by looking for "files" or "folder" property for that specific Item in response. Refer drive Items resource.
GET /drives/{drive-id}/items/{item-id}/children
Java Code Snippet:
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
DriveItemCollectionPage children = graphClient.drives("{drive-id}").items("{item-id}").children()
.buildRequest()
.get();
References: List drives, List children of a driveItem
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.