Graph API - Restoring a DriveItemVersion as a new file in OneDrive

Stephan Methner 116 Reputation points
2021-04-06T10:54:29.707+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 also can get some detail information about a specific version with "/versions/x.0.

Now I would like to restore one of these DriveItemVersions as a new OneDrive file (in another folder) - not overwriting my actual version.

Or if this is not possible - download that version file.

I'm developing a browser only React app (not node.js) and even have problems with getting the content of such a file:

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

@Danstan

I appreciate any 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,734 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-04-07T07:12:54.757+00:00

    Hi @Stephan Methner ,
    The restore operation will only restore the file to the location of the current file, and cannot restore the file to other folders or libraries. To download files from OneDrive in a JavaScript app you cannot use the /content API, since this response with a 302 redirect. A 302 redirect is explicitly prohibited when a CORS preflight is required, such as when providing the Authorization header.
    You could take a look at this document:Using the OneDrive API in JavaScript apps (CORS support)


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments