question

StephanMethner-8164 avatar image
0 Votes"
StephanMethner-8164 asked saldana-msft edited

Graph API - Getting access to a OneDrive DriveItemVersion

Hi there,

I'm using the Graph API to access Excel files in my OneDrive (works great!).

Actually I'm trying to access older versions of my Excel files. I can get a list with "/versions". I can get some detail information about a specific version with "/versions/x.0.

But getting the content is not working for me (no specific error message)

Graph Explorer

    https://graph.microsoft.com/v1.0/me/drive/items/01Y5BOJUKNFSJVM6VB6J.../versions/2.0/content

or in code

 let res = await client.api("/me/drive/items/01Y5BOJUKNFSJVM6VB6J.../versions/2.0/content").get();


In the end I would like to access workbook elements inside the version driveItem. Something like:

 let res = await client.api("/me/drive/items/01Y5BOJUKNFSJVM6VB6J.../versions/2.0/driveItem/workbook/names").get();

Is it possible to get access to driveItems based on a DriveItemVersion?

Or download such an old version?

I appreciate your help. Thanks in advance

Best
Stephan


microsoft-graph-sdkmicrosoft-graph-filesmicrosoft-graph-sites-lists
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Danstan-MSFT avatar image
0 Votes"
Danstan-MSFT answered

Using Download contents of a DriveItemVersion you can download content of the desired version. Note that you can only download older versions through this API and not current version. Also the version has to be listed in https://graph.microsoft.com/v1.0/me/drive/items/01TLIPQRK4L.../versions

On Graph Explorer, the request fails with no message which can be the way Graph Explorer handles streams.
Try on postman by clicking Send and Download instead of Send.
79236-postman-download-file.png
Using the SDK, the response is a stream so you wanna write to a file (JavaScript).

 const client = Client.init(options);
    
 let stream = await client.api('/me/drive/items/01TLIPQRK4L.../versions/1.0/content').get();
 const file = fs.createWriteStream('file.xlsx');
 stream.pipe(file)



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

StephanMethner-8164 avatar image
0 Votes"
StephanMethner-8164 answered Danstan-MSFT commented

Hi Danstan,

thanks a lot. Is it perhaps possible to restore this file somewhere in the OneDrive (not overwriting the actual version)? Without downloading it to my local machine.

I'm developing a React app (not a node.js). If it is not possible to write it to OneDrive - do you know a way to download to my local machine using react (axios, fetch api)?

Best
Stephan

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

For this I suggest you open a new question. If my answer was helpful please consider accepting to help other community members.

0 Votes 0 ·