Veeam Backup for Microsoft Office 365 RESTful API: OneDrive restores

Veeam Backup for Microsoft Office 365 RESTful API: OneDrive restores

This post is based upon the entire organization backup job which we made in part 1, we will dig deeper on how to perform restores for OneDrive for Business.

Starting a restore session

Before we can actually restore a file or folder, we need to start a restore session. We will leverage the organization ID and perform a POST request against “/v2/Organizations/{organizationID}/action“. This will start a Veeam Explorer in the background and return a restore session ID. The restore session ID will be used during the restore process.

To start the restore session, we will leverage the following JSON which starts the Veeam Explorer for OneDrive for Business.

{
  "explore": {
    "datetime": "2019.02.19",
    "type": "veod"
  }
}

As we want to restore specific OneDrive for Business items (either a file or folder), we leverage the type VEOD which is short for Veeam Explorer for OneDrive for Business.

This will start the restore session in the background and will result in a 201 response code stating the Veeam Explorer has started. The output contains a restore session ID which we will use in the next parts to perform restores.

Restore session started

Restore possibilities

With the restore session ID, we can now perform the restores as needed. We can restore multiple objects:

  • Complete OneDrive for Business accounts
  • Specific files or folders
  • Multiple files or folders at once

In the following examples, we will restore a complete account. Before we can restore the account, we need to get the OneDrive account ID. We can get this via “/v2/RestoreSessions/{restoreSessionID}/Organization/OneDrives” where we replace the restore session ID. This will result in a list of available OneDrive accounts. Select the OneDrive account you want to restore and copy the ID as it will be used in the following API requests.

OneDrive response

Restore to original location

Now that we have the OneDrive account ID and the restore session ID, we can start the actual restores. A restore is performed by making a POST call against “/v2/RestoreSessions/{restoreSessionID}/organization/OneDrives/{onedriveID}/action“. The JSON to restore to the original location is defined below, make sure you replace the values needed for the username and password accordingly.

{
  "restoretoOriginallocation":  {
    "userName": "niels.engelen@XXXX.onmicrosoft.com",
    "userPassword": "C00lpa$$word",
"documentVersion": "last",
"documentAction": "keep",
  }
}

There are 2 additional parameters available. “documentVersion‘ and ‘documentAction‘, these can be used to restore a previous version where as the action can be “keep” or “overwrite”.

Upon performing this request, you will get a 200 response code once the restore has been performed.

Exporting an account

We can export the OneDrive for Business account by posting the following JSON against “/v2/RestoreSessions/{restoreSessionID}/organization/OneDrives/{onedriveID}/action“. This will give the output in an application/octect-stream which can be parsed by your programming language of choice.

{
  "save": "null"
}

Working with individual files and folders

If you want to restore a specific file or folder, you can perform a request against “/v2/RestoreSessions/{restoreSessionID}/organization/OneDrives/{onedriveID}/Documents” or “/v2/RestoreSessions/{restoreSessionID}/organization/OneDrives/{onedriveID}/Folders” to get a list of all available files and folders.

The example below will export a document to a ZIP file. To restore the file we perform a POST request against “/v2/RestoreSessions/{restoreSessionID}/Organization/OneDrives/{onedriveID}/Documents/{fileID}/Action” containing the following JSON.

{
  "save" : {
    "asZip" : "true"
  }
}

This will result in a ZIP file available for download containing the specific file.

What’s next?

In the next part, we will take a look at restoring SharePoint. You will learn how to find and restore an item (files, folders and lists). We will perform a restore to the original location and export to the item as a ZIP file.

Missed a part?

Niels Engelen on GithubNiels Engelen on Twitter
Niels Engelen
Working as a Principal Analyst in Product Management for Veeam Software with an interest in anything virtual and cloud with a strong focus on AWS, Azure and Microsoft 365. He is also a VMware Certified Professional, a Veeam Certified Architect and gained the VMware vExpert award (2012-2022).
Comments are closed.