Onedrive for Business url for the current user using (JSOM or Rest Query)

Iron Contributor

how do i get Onedrive for Business url for the current user using (JSOM or Rest Query)

 

I have created a list and i want to users list directly the url will be appended by Lists/Quick%20Links

where Quick%20Links is the name of list i have created. This should work for any user as i already a ps script which will create the list in their respective onedrives.

 

 

Thanks

3 Replies

i am getting the following when pasted in browser 

{
  "error": {
    "code": "InvalidAuthenticationToken",
    "message": "Access token is empty.",
    "innerError": {
      "request-id": "ba5d6457-fb10-4523-95e9-83ded440864d",
      "date": "2019-02-19T15:54:00"
    }
  }
}

You have to authenticate against Microsoft Graph to access the endpoints.

 

You can do this easily in SPFx with the MSGraphClient, which you can give Graph access by configuring the permissions in your package-solution.json file and approving when you install: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aad-tutorial 

 

If you're not in SPFx, there are other ways to access authenticate against Microsoft Graph: https://docs.microsoft.com/en-us/graph/auth-overview

 

 

I guess it really depends on your situation though. A quick-fix way to do this would be to just parse the user's email address and build the URL yourself. The URL follows this general scheme:

https://tenant-my.sharepoint.com/personal/user_tenant_com/Documents where non alphanumeric characters in the email address become "_"

 

I have no idea if that URL scheme is subject to change or if there are special cases, so I wouldn't consider building the URL like that from an email address a permanent solution.