I am looking for assistance to find out how I can download and move a OneDrive file that is accessed through a shared directory, via the shared link method of sharing.
I have two users:
- user ‘A’ who is a Microsoft Consumer and has a regular OneDrive account and will host a csv file ‘test.csv’ in a folder ‘toshare’
- and user ‘B’ who is also a regular Microsoft Consumer who should use the graph API to download test.csv and then move the file to a subdirectory /toshare/archive
Aside: I am currently using the chrome app “advanced REST client” to manually make the REST calls, and am getting Authenticated OAuth BEARER tokens by inspecting network traffic from Microsoft’s online “Graph Explorer” tool. After we understand the calls, we’ll integrate it into our Java app.
I have succesfully followed the instructions here:
to view the folder contents.
To be more explicit, user ‘A’ has went into OneDrive and has right clicked the folder ‘toshare’ and selected shareLink. I have converted the shareLink to a share token and then used the following API call with the Graph API as user ‘B’:
this shows me all the files in the directory, which includes ‘test.csv’
Now, using this information, how can I download test.csv? Assuming user ‘B’ doesn’t know the name of the file, but can identify it by being a .csv file (we can do this in code). There does not appear to be much documentation on how to download the files through a share.
The closest I’ve gotten was to take the “webUrl” attribute of the children object for my file, and then turn that into a share token and call
This will show me the file meta-data. and then I try to download it by roughly following the api documentation to download https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_downloadcontent
This is interesting because this works if I make the call with user ‘A’ but does not work for user ‘B’ who instead gets a 403 in advanced REST client. (If I run it in Graph Explorer, I get “The site in the encoded share URI is invalid.” instead, which I’ve discovered with other experimentation, really means there’s an authorization issue.)
At this point I’m rather stuck. After downloading the file, I also would like to move it into a subdirectory, denoting that it has already been read in. I’d also like to get this working for OneDrive for Business, but that seems to be another set of challenges that I’ll leave for another day.
Any insight would be great thanks,
Get this bounty!!!