Path-based addressing of drives in graph

Viktor Rosvall 1 Reputation point
2022-09-20T12:49:00.413+00:00

Hello,

I'm trying to access the files of drives by the name of the drive and site.

Setup:
Host - wvgsg.sharepoint.com
Site - TheLanding
Drive - Test

I can use this URL to list all drives a site has access to:
https://graph.microsoft.com/v1.0/sites/wvgsg.sharepoint.com:/sites/TheLanding:/drives

   {  
       "description": "A testing document library",  
       "id": "b!DVGGM-_KkUq4v2cyNId7Qx1d-mCSpvlIo4R12S5zDlAhreGzy6w4TZoC9t-cexvv",  
       "name": "Test",  
       "webUrl": "https://wvgsg.sharepoint.com/sites/TheLanding/Test",  
       "driveType": "documentLibrary",  
   },  
   {  
       "description": "Files on Sharepoint site",  
       "id": "b!DVGGM-_KkUq4v2cyNId7Qx1d-mCSpvlIo4R12S5zDlDQ6yOJeVONRbbpySNc0JYm",  
       "name": "The Landing files",  
       "webUrl": "https://wvgsg.sharepoint.com/sites/TheLanding/The%20Landing%20files",  
       "driveType": "documentLibrary",  
   },  

Now I want to access either of those 2 drives by using an URL that looks something like:

https://graph.microsoft.com/v1.0/sites/wvgsg.sharepoint.com:/sites/TheLanding:/drives:/Test

But I'm left with a Bad request - 400

   {  
       "error": {  
           "code": "BadRequest",  
           "message": "Resource not found for the segment 'drives:'.",  
           "innerError": {  
               "date": "2022-09-20T12:43:24",  
               "request-id": "013cdfd6-a5ff-4337-a236-0eb39f14b8e3",  
               "client-request-id": "8f0b5c98-339a-7755-8637-4775b7704f1e"  
           }  
       }  
   }  

The reason why I need to use the Names and not IDs is because the user is expected to input their site and drive names.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,291 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,681 Reputation points Microsoft Vendor
    2022-09-20T16:18:47.613+00:00

    Hi @Viktor Rosvall ,

    You can get drive only with driveId not by using name get-a-drive-by-id.
    Alternatively, you can make use of get a list from a SharePoint Online list title, by simply using GET /sites/{site-id}/lists/{list-title}/drive.

    243121-image.png

    Refer to list-relationships-drive, Only present on document libraries. Allows access to the list as a drive resource with driveItems.

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