How to access User drive(s) via Graph API?

Adz 286 Reputation points
2022-09-20T16:49:38.107+00:00

I am trying to access an organisations User drive(s)

I am getting this error:

Error code: BadRequest
Error message: Unable to retrieve user's mysite URL.
GET https://graph.microsoft.com/v1.0/users/{user-id}/drives

The documentation states

To access a user's OneDrive or OneDrive for Business, your app must request the drive relationship on the User resource.

Can someone explain what this means to me please? I am unable to do this on the AD Applications Permissions UI. How can i request the "drive" relationship on a User resource?

https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get?view=odsp-graph-online#get-a-users-onedrive

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. HarmeetSingh7172 4,831 Reputation points
    2022-09-20T17:42:20.657+00:00

    Hi @Adz

    Hope you're doing well.

    As you are using Client Credentials Flow, please verify the below:

    • Check if the user is enabled with valid license
    • If user has a license to use OneDrive, is not provisioned
    • If a user's OneDrive is not provisioned but the user has a license to use OneDrive, this request will automatically provision the user's drive, when using delegated authentication

    Note: Guest users won't have a dedicated OneDrive.
    Also, please use GET /users/{idOrUserPrincipalName}/drive instead of /drives

    Documentation Reference: Get User's OneDrive

    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".

    0 comments No comments

  2. Tong Zhang_MSFT 9,256 Reputation points
    2022-09-21T06:15:00.427+00:00

    Hi @Adz ,

    I agree with HarmeetSinghMSFT-7172's answer, if you want to Get a user's OneDrive, please note the following:

    243229-01.png

    Also, please make sure the user-id is entered correctly. In my test, the same error will occur if you enter the wrong user-id.

    Please reference to this document: Get a user's OneDrive

    My test result:
    243311-02.png

    Hope it can help you. Thanks for your 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.



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.