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

%3CLINGO-SUB%20id%3D%22lingo-sub-324453%22%20slang%3D%22en-US%22%3EOnedrive%20for%20Business%20url%20for%20the%20current%20user%20using%20(JSOM%20or%20Rest%20Query)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-324453%22%20slang%3D%22en-US%22%3E%3CP%3Ehow%20do%20i%20get%20Onedrive%20for%20Business%20url%20for%20the%20current%20user%20using%20(JSOM%20or%20Rest%20Query)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20a%20list%20and%20i%20want%20to%20users%20list%20directly%20the%20url%20will%20be%20appended%20by%26nbsp%3BLists%2FQuick%2520Links%3C%2FP%3E%3CP%3Ewhere%26nbsp%3BQuick%2520Links%20is%20the%20name%20of%20list%20i%20have%20created.%20This%20should%20work%20for%20any%20user%20as%20i%20already%20a%20ps%20script%20which%20will%20create%20the%20list%20in%20their%20respective%20onedrives.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353234%22%20slang%3D%22en-US%22%3ERe%3A%20Onedrive%20for%20Business%20url%20for%20the%20current%20user%20using%20(JSOM%20or%20Rest%20Query)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353234%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20have%20to%20authenticate%20against%20Microsoft%20Graph%20to%20access%20the%20endpoints.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20do%20this%20easily%20in%20SPFx%20with%20the%26nbsp%3BMSGraphClient%2C%20which%20you%20can%20give%20Graph%20access%20by%20configuring%20the%20permissions%20in%20your%20package-solution.json%20file%20and%20approving%20when%20you%20install%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fspfx%2Fuse-aad-tutorial%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fspfx%2Fuse-aad-tutorial%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you're%20not%20in%20SPFx%2C%20there%20are%20other%20ways%20to%20access%20authenticate%20against%20Microsoft%20Graph%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fauth-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fauth-overview%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20guess%20it%20really%20depends%20on%20your%20situation%20though.%20A%20quick-fix%20way%20to%20do%20this%20would%20be%20to%20just%20parse%20the%20user's%20email%20address%20and%20build%20the%20URL%20yourself.%20The%20URL%20follows%20this%20general%20scheme%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftenant-my.sharepoint.com%2Fpersonal%2Fuser_tenant_com%2FDocuments%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftenant-my.sharepoint.com%2Fpersonal%2Fuser_tenant_com%2FDocuments%3C%2FA%3E%20where%20non%20alphanumeric%20characters%20in%20the%20email%20address%20become%20%22_%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20no%20idea%20if%20that%20URL%20scheme%20is%20subject%20to%20change%20or%20if%20there%20are%20special%20cases%2C%20so%20I%20wouldn't%20consider%20building%20the%20URL%20like%20that%20from%20an%20email%20address%20a%20permanent%20solution.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353214%22%20slang%3D%22en-US%22%3ERe%3A%20Onedrive%20for%20Business%20url%20for%20the%20current%20user%20using%20(JSOM%20or%20Rest%20Query)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353214%22%20slang%3D%22en-US%22%3E%3CP%3Ei%20am%20getting%20the%20following%20when%20pasted%20in%20browser%26nbsp%3B%3C%2FP%3E%3CPRE%3E%7B%0A%20%20%22error%22%3A%20%7B%0A%20%20%20%20%22code%22%3A%20%22InvalidAuthenticationToken%22%2C%0A%20%20%20%20%22message%22%3A%20%22Access%20token%20is%20empty.%22%2C%0A%20%20%20%20%22innerError%22%3A%20%7B%0A%20%20%20%20%20%20%22request-id%22%3A%20%22ba5d6457-fb10-4523-95e9-83ded440864d%22%2C%0A%20%20%20%20%20%20%22date%22%3A%20%222019-02-19T15%3A54%3A00%22%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-352586%22%20slang%3D%22en-US%22%3ERe%3A%20Onedrive%20for%20Business%20url%20for%20the%20current%20user%20using%20(JSOM%20or%20Rest%20Query)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-352586%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20get%20it%20from%20the%20Graph%20API%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fusers%2F%3CUSER%3E%2Fdrive%2FwebUrl%3C%2FUSER%3E%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular 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
Highlighted
Highlighted

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"
    }
  }
}
Highlighted

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.