Graph API - Getting access to a OneDrive DriveItemVersion

Stephan Methner 116 Reputation points
2021-03-18T00:03:43.357+00:00

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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,832 questions
0 comments No comments
{count} votes

Accepted answer
  1. Danstan Onyango 3,741 Reputation points Microsoft Employee
    2021-03-18T16:17:16.02+00:00

    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)  
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Stephan Methner 116 Reputation points
    2021-03-18T16:50:56.107+00:00

    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